Functions
Basic Functions in Python
Determine whether a number is even or odd
def evenOdd(x):
if (x % 2 == 0):
print("even")
else:
print("odd")
# Examples
evenOdd(4)
evenOdd(17)
Find Word Count in a string, returned as an integer
def wordcount(str) -> int:
## Split the words
words = len(str.split())
# If words = 0, raise exception
if words == 0:
# raise error
raise ValueError('`words` must contain at least one word')
return words
# Example
alphabet = "The quick brown fox jumped over the lazy dog."
wordcount(alphabet)