I'm trying to restart a program using an if-test based on the input from the user.
This code doesn't work, but it's approximately what I'm after:
answer = raw_input('Run again? (y/n): ') if answer == 'n': print 'Goodbye' break elif answer == 'y': #restart_program??? else: print 'Invalid input.' What I'm trying to do is:
- if you answer y - the program restarts from the top
- if you answer n - the program ends (that part works)
- if you enter anything else, it should print 'invalid input. please enter y or n...' or something, and ask you again for new input.
I got really close to a solution with a "while true" loop, but the program either just restarts no matter what you press (except n), or it quits no matter what you press (except y). Any ideas?