![]() |
Won't open from desktop - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Won't open from desktop (/thread-10900.html) |
Won't open from desktop - st3m0n - Jun-12-2018 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. RE: Won't open from desktop - buran - Jun-12-2018 there is missing closing parenthesis on line#27 so this is not the code that runs in IDLE RE: Won't open from desktop - st3m0n - Jun-12-2018 True enough... Didn't think to just copy and paste it tbh. Here's a copied and pasted version of it # Guess My Number # # The computer picks a number at random 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 import random 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.") RE: Won't open from desktop - buran - Jun-12-2018 this one works for me. I guess you have more than one version of the file (e.g. the one from previous post and this one..) also, make sure you don't have file named random.py in the same folder RE: Won't open from desktop - st3m0n - Jun-12-2018 There was an extra one which I deleted, and no random.py but it still won't work. All the other ones I have saved that I tried still work too :S It turns out that I deleted the good save and was left with one with syntax errors in 3 places, thank you for your help :), deleting the other save did the trick nicely. |