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.
# 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.")Thank you for reading my thread, and for any answers you give.