0
How do I skip lines or go back to lines in a loop.
Making a video game. One portion is attack and one portion is run. If they input "attack" I can get the program to use an if statement to say a weapon (knife). But how can I get it to stop after run (for input "run" I only want one option)? I tried adding "continue", etc. but it didnt seem to work. Any help appreciated. print("What will you do? Run or attack?") x = input() if x == ("attack"): print("You attack. How do you attack?") elif x == ("run"): print("You run. Should stop here.") y = input() while True: if x == ("attack"): print("You will attack ") if y == ("knife"): print("with a knife") break
3 odpowiedzi
0
Thanks Swim and Jay,
I've followed your advice and cleaned up a lot, so thanks for that.
Unfortunately, I keep getting an error message for line-26:
"Teraceback (most recent call last):
File "..\Playground\", line 26, in <module>
Q1 = input()
EOFError: EOF when reading a line"
Originally it said my indentaions weren't the same, but have since fixed that. Any idea what's going on? Code is pasted below. Thanks for any additional help anyone could provide.
choice_1 = input()
if choice_1 == ("fight"):
print("You chose fight.")
while choice_1 == ("fight"):
print("You can choose to attack with hooves or your horn? Which will it be?")
break
choice_2 = input()
if choice_2 == ("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_2 == ("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 tiring.")
elif 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 == ("yes"):
print("Yes! They do! Now, let's get that slime monster!")
#if Q1 == ("no"):
# print("Try again. Do unicorns have horns?")