#factorial(4) would return 24 (4*3*2*1). def factorial(num): factorial_total = 1 for i in range(1,num+1): factorial_total = i*factorial_total return factorial_total def recfactorial(num): # base case if (num == 0) or (num == 1): return 1 # recursive case return num * recfactorial(num-1) #Message to encode: Python is fun! #Message encoded: 80 121 116 104 111 110 32 105 115 32 102 117 110 33 def encode_msg(message): encoded_msg = "" for character in message: encoded_msg += str(ord(character)) + " " return encoded_msg def main(): user_input = input("Factorial of what? ") print(user_input + "! = ", factorial(int(user_input))) print(user_input + "! = ", recfactorial(int(user_input))) user_input = input("Message to encode: ") print("Message encoded: ", encode_msg(user_input)) user_input = int(input("Enter a number (or '0' to finish): ")) numbers = list() while(user_input != 0): numbers.append(user_input) user_input = int(input("Enter a number (or '0' to finish): ")) #rnge = max(numbers) - min(numbers) numbers.sort() rnge = numbers[-1] - numbers[0] print("The range is: " + str(rnge)) def mode(numbers): current_mode = numbers[0] # for each number in set(numbers) # number_count = numbers.count(number) # if (number_count is > numbers.count(current_mod) # update current mode return current_mode main()