# Class 7 Examples # example of a very basic function (no parameters, no return value) def welcome(): '''prints an intro to our program''' print('Welcome user!') print("We're learning functions!") print('Tomorrow... who knows!') # Don't do this: #welcome() #return "I just finished printing!" # Using arguments and return values def sqrt(num): '''returns the sqrt of num''' return int(num)**.5 # Takes a number and returns True if that number is even, otherwise false def isEven(num): if (int(num)%2 == 0): # num is even return True else: # num is odd return False # returns whether a num is even or odd def isOdd(num): return not isEven(num) ''' def isOdd(num): if (num%2 != 0): return True return False ''' def worthless(): # This function doesn't anything print("Now I'm worthless") # returns the value of parameters num1 added to num2 def add(num1, num2): added_value = num1 + num2 return added_value num1 = int(input("First num: ")) num2 = int(input("Second num: ")) print(add(num1, num2)) print("Is ", num1, " odd: ", isOdd(num1), sep="") added_value = add(1234124, 143453) print(added_value) welcome() #welcome_return = welcome() # Equivalent lines: #print(welcome()) #print(welcome_return) #test = sqrt(16) #print("Sqrt of 16:", test) #test2 = sqrt("9") #print(sqrt("9")) num = input("Give me a number: ") if (isEven(num)): print("This number is even") else: print("This number is odd") print("Before, I was worthless") worthless() print("Now I'm not")