- 1

Stop after a "no" if input?

When I run this code (an RPG) I want the code to stop if they enter "no" for "Do unicorns have horns?". I added a "break" but it wouldn't work? I also changed the "if" statement to a "while" statement but didn't work. Any ideas? It's line 8. Any help appreciated:). if choice_1 == ("run"): print("You chose run. Unicorns can run fast, but let's do a challenge for more power next time! Remember, your friends in the forest need you! Here is the first question: Do unicorns have horns?") Q1 = input() if Q1 == ("no"): print("Try again. Do unicorns have horns?") elif Q1 == ("yes"): print("Yes! They do! Now, let's get that slime monster!") if Q1 == ("yes"): print("Hoof or horn?") choice_3 = input() if choice_3 == ("hoof"): print("""You chose hoof! You kick at the slime with your four hooves! Now the slime attacks you! Get ready! You dodge the slime monster, but it did one point's worth of damage. You still have nine points! Now it's your turn! You kick at the slime monster again! Hit! The slime monster is running away! Good job! Remember, hoof attacks are less powerful than horn attacks, but you can attack again and again!""") elif choice_3 == ("horn"): print("You attack with your horn! The slime monster ran away! Good job! But remember, your horn attacks are more powerful but also limited because they are more tirin

15th May 2019, 2:49 AM
tristach605
tristach605 - avatar
2 Answers
+ 1
word of advice, just send the codes that has the problem. giving all the codes just makes it more confusing for people to help. if you want to exit a program if they inputted a "no" then i suggest using the exit() function as below. choice = input() if choice == "no": exit() elif ... : . . .
15th May 2019, 8:10 AM
Shen Bapiro
Shen Bapiro - avatar
0
Thanks lvl 1 crook. That's some good advice.
15th May 2019, 10:56 PM
tristach605
tristach605 - avatar