I decided to make a mini-game as my 1st program since I am very new to python. The user must enter yes to start the game if you type no the program is supposed to say "bye-bye" and end. if anything else is entered it print "I do not understand bye-bye" However when I enter no it plays the else statement along with what was supposed to play when it enters no. How do I fix this? This is my program (sorry if it's a little long). You can run it and type no to see what I mean.
light_on = False
door_open = False
print('hello')
start = input('Would you like to play a game yes or no ? ').lower()
if start == 'no':
print('bye bye')
while start == 'yes':
print('Type help if you do not know how to play')
command = input('Command?: ').lower()
if command == 'help':
print('''
on = turn light on
off = turn light off
open = open door
close = close door''')
elif command == 'on':
if light_on:
print('The light is already on')
else:
light_on = True
print('The light is bright and warming')
elif command == 'off':
if not light_on:
print('the light is already off')
else:
light_on = False
print('the room is dark and scary')
elif command == 'open':
if door_open:
print('the door is already open!')
else:
door_open = True
print('the hallway is so dark you cannot see')
elif command == 'close':
if not door_open:
print('the door is already closed!')
else:
door_open = False
print('you slammed the door shut')
elif command == 'quit':
print('bye bye')
break
else:
print('I do not understand')
else:
print('I do not understand bye bye')
Aucun commentaire:
Enregistrer un commentaire