Mar-09-2020, 03:46 PM
(Mar-09-2020, 01:50 PM)snippsat Wrote: So the my_game() could have the content of guess the number code.understood. i tried it and the result was perfect. Thank You SO much.
heres my finalised code.
import random def my_game(): print("Start by guessing the number I chose. It is between 1 and 100.") secret_number = random.randint(1, 100) guess, tries = 0, 0 while guess != secret_number: guess = int(input("Take a guess: ")) if guess > secret_number: print ("Lower") elif guess < secret_number: print ("Higher") tries += 1 print('You guessed it! The number was', guess, 'in', tries,' tries') input('Push enter to retun to menu') def menu(): while True: print('(1) Play game') print('(Q) Quit') choice = input('Enter your choice: ').lower() if choice == '1': my_game() elif choice == 'q': return False else: print(f'Not a correct choice: {choice},try again') if __name__ == '__main__': menu()