我在使用 1 行代码时遇到问题,我一遍又一遍地运行它,但我不知道我做错了什么,我认为这是if
声明,但我不确定。我遇到问题的那一行在评论中。我不知道如何编写它,所以它可以正常工作。
import random
print"Hello hero, you are surrounded by a horde of orcs"
print"that span as far as the eye can see"
print"you have 5 health potions, 200 health"
print"you can either fight, run, or potion"
h=200 #health
w=0 #wave
o=0 #orc
p=5 #potion
while h>=0:
print"you run into a horde of orcs what will you do?"
a=raw_input("fight, run, potion")
if a=="fight":
print"you draw your sword and begin to fight"
d=random.randint(1, 20)
w+=1
o+=1
p=5
h-=d
print"you survive this horde"
print("you have, "+str(h)+" health left")
elif a=="potion":
print"you have used a potion"
h+=20
p=p-1
print"you have recovered 20 health"
print("you now have, "+str(h)+" health")
if p==0: #supposed to be if potion = 0 print (you dont have any left)
print"you dont have any left"
elif a=="run":
h-=5
print"you got away but suffered 5 damage"
print("you have, "+str(h)+" health left")
print"you have fought well but alas hero you were defeated"
print("you survived, "+str(w)+" waves and have killed, "+str(o)+" orcs")