0

I am only starting out programming and currently making a text game. I know there is no goto command in python and after doing some research I understood that I have to use loops to replace that command but it just isn't doing what i was hoping it would do. Here's my code:

print('Welcome to my bad game!')
print('Please, press Enter to continue.')
variable=input()
if variable == '':
    print('You are in a dark forest. You can only choose one item. Press 1 for a flashlight and press 2 for an axe.')
while True:
    item=input()
    if item=='2':
        print('Bad choice, you lost the game.')
        quit()
    if item=='1':
        print('Good choise, now you can actually see something.')

So my problem with this is that if the player chooses the 'wrong' item the program just kills itself but I would want it to jump back to the beginning. I actually don't know if this is even possible but better ask than just wonder.

OlliJ
  • 1
  • instead of while True, you would loop on a condition, like while playing: and instead of quit(), it could be playing = False – Kenny Ostrom May 08 '16 at 19:02
  • From what line would you execute again? – Jongware May 08 '16 at 19:03
  • I recommend seeking out a basic tutorial (the [official Python tutorial](https://docs.python.org/3.5/tutorial/index.html) is quite good). Whenever you have doubts as to whether something is possible, browse through the topic listing - you'll probably find what you're looking for. – TigerhawkT3 May 08 '16 at 19:04

2 Answers2

0

If you mean to the beginning to the loop, just leave out the call to quit. If you mean to the beginning of the program, then you'll need a loop around that as well.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
-1

Instead of quit you could use 'continue' to loop back to your while. But it's not clear from this example what you want the while to do.

Phil Hord
  • 12,780
  • 1
  • 26
  • 30