Apr-06-2017, 11:03 PM
Hey all! Created this fun numbers game that will return some facts about 20 input or random numbers.
# Description of program: # Ask the user to enter 20 numbers or have them generated # randomly by the program. After they are entered/generated # reveal the results of lowest, highest, total, # and the average of the numbers selected/inputed. import random import time import os import sys # main module def main(): # local variables choice = True total_count = 20 low_count = 1 high_count = 10000 # Welcome statement to user print("\n***Welcome to the Number Analysis Genie***".upper()) print("\n- This Genie will tell you your lowest number, highest number, \n" "total of all numbers, and the average of all numbers. - \n") print("- You can select your own", total_count, "random numbers \n" " or have them randomized!! - \n") # While loop to control either random or user input numbers while choice: print("Please select below: \n" "(1) Self input", total_count, "numbers. \n" "(2) Randomize", total_count, "numbers between 1 and 10,000. ") selection = input("\n***selection please:") if selection == '1': choice = False # Call the input number module for user input_number(total_count) elif selection == '2': choice = False # Call the random number module for user random_number(total_count, low_count, high_count) else: print('Wrong selection please try again! \n') choice = True # Call try again module to allow user to try again or close program try_more() # Random number module where program will generate 20 random numbers def random_number(total_count, low_count, high_count): # Local variables and list random_count = 0 random_list = [] # Instructions for user print('Please hit enter when you are ready to generate ' 'your numbers!!') input('') # For statement to begin randomizing 20 numbers with .5 delay for x in range(total_count): random_count = random.randint(low_count, high_count) random_list.insert(0, random_count) print(random_count) time.sleep(.5) print('\n ***wow!! that was awesome!!***'.upper()) print('Hit enter to see your results...') input() # Call calculation module to process random list 20 numbers calc(random_list) # Input number module where user will input 20 numbers def input_number(total_count): # local variables and lists input_list = [] number = 0 count = 0 # Instructions for user print('Please hit enter when you are ready to generate' 'your numbers!!') print('**Please remember, only whole numbers between 1 and 10,000') # For statement to begin sequencing of 20 number only input for count in range(total_count): number = int(input('Number ' + str(count + 1) + ' of 20: ')) input_list.insert(0, number) print('\n ***wow!! that was awesome!!***'.upper()) print('Hit enter to see your results...') input() # Call calculation module to process input list 20 numbers calc(input_list) # Calculations module used for either input or random modules def calc(numbers): # Local variables low = 0 high = 0 total = 0 average = 0.0 # Calculations for low, high, total and average low = min(numbers) high = max(numbers) total = sum(numbers) average = total / 20 # Display of low, high, total and average print(' Low of Numbers:', format(low, ',')) print(' High of Numbers:', format(high, ',')) print(' Total of Numbers:', format(total, ',')) print('Average of Numbers:', format(average, ',.2f')) # Try again module to restart or end program based off of user control def try_more(): try_again = True # While statement to begin asking customer to try again while try_again: print('\n') try_again = input('Do you want to try again? Yes(y) or No(n)?') if try_again == 'y': os.system('cls') main() elif try_again == 'n': print('Thanks for playing!!') time.sleep(2.0) sys.exit(0) else: print('Wrong Selection, try again!') try_again = True # Call main module main()