Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help for guessing game code
#5
(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()
Reply


Messages In This Thread
Help for guessing game code - by Kronos - Mar-09-2020, 11:39 AM
RE: Help for guessing game code - by snippsat - Mar-09-2020, 12:59 PM
RE: Help for guessing game code - by Kronos - Mar-09-2020, 01:24 PM
RE: Help for guessing game code - by snippsat - Mar-09-2020, 01:50 PM
RE: Help for guessing game code - by Kronos - Mar-09-2020, 03:46 PM
RE: Help for guessing game code - by snippsat - Mar-09-2020, 04:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  needing some help to write some code for a game calculator rymdaksel 2 1,736 Mar-08-2025, 03:02 AM
Last Post: bevisandrew
  word guessing game, hints STUdevil 1 1,948 Oct-12-2024, 01:53 AM
Last Post: menator01
  Problem with my pong game code Than999 8 6,187 May-15-2022, 06:40 AM
Last Post: deanhystad
Question Beginner Boolean question [Guessing game] TKB 4 4,647 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Unable to count the number of tries in guessing game. Frankduc 7 3,327 Mar-20-2022, 08:16 PM
Last Post: menator01
  Music Selection Game Code WyattH 3 3,352 Jul-20-2020, 11:16 AM
Last Post: ndc85430
  Guessing game problem IcodeUser8 7 5,786 Jul-19-2020, 07:37 PM
Last Post: IcodeUser8
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 3,956 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Python Help - Guessing Game JamieT 5 4,412 Apr-16-2020, 01:30 PM
Last Post: deanhystad
  Guessing game kramon19 1 2,787 Mar-25-2020, 04:17 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020