1

So I'm trying to make a little fun code to test my skills, and I'm trying to get the first if statement to continue to the next if statement, that is if they answer yes. If they answer anything other than yes, the code ends. How do I change it so the code actually ends if they answer incorrectly?

print('Would you like to begin?')

answer = input()

if answer == 'yes':
    print('What is your name?')
    #continue to the next portion when if statement is true
else:
    print('ok')
   #break the code when else statement is true
name = input()

if name == 'Test':
    print('Congratulations! You won!')
else:
    print('Good try. The answer was Test.')
Doctor Pickle
  • 63
  • 1
  • 8

1 Answers1

1

Replace #break the code when else statement is true with import sys; sys.exit(0).

If they answer 'yes', it will simply continue to name = input().

Ceasar
  • 22,185
  • 15
  • 64
  • 83