Jun-12-2018, 07:00 PM
I'm using python 3.6.5 to learn programming, and have come across a bit of a problem with my most recent lesson. The objective of the lesson is to create a small game where you input for the programme to randomly select a number between 1 and 100, with a loop created so that you can guess again until you get it right with the programme telling you whether to guess higher or lower, with a congratulations once you finally get it right. I initially had a problem where it wouldn't run through Run Module/f5, due to invalid syntax, but I sorted that out. Now, however, while it works exactly as it should when I "run module" (except press the enter key to exit, since it just puts me on a new line), it won't work when I try to open it from my desktop, it just flashes up for a fraction of a second, and then disappears. Any help you can give will be greatly appreciated. Here's the code I put in.
Thank you for reading my thread, and for any answers you give.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# Guess My Number # # The computer picks a random number between 1 and 100 # The player tries to guess it and the computer lets # the player know if the guess is too high, too low # or right on the money print ( "\tWelcome to 'Guess My Number'!" ) print ( "\nI'm thinking of a number between 1 and 100." ) print ( "Try to guess it in as few attempts as possible.\n" ) # set the initial values the_number = random.randint( 1 , 100 ) guess = int ( input ( "Take a guess: " )) tries = 1 # guessing loop while guess ! = the_number: if guess > the_number: print ( "Lower..." ) else : print ( "Higher..." ) guess = int ( input ( "Take a guess: " ) tries + = 1 print ( "You guessed it! The number was" , the_number) print ( "And it only took you" , tries, "tries!\n" ) input (\n\nPress the enter key to exit.") |