我正在尝试制作游戏,但当我问玩家是否想要捍卫或攻击时,我会不断收到此错误
defend_attack=input("Would you like to defend (you only take a quarter of the damage) or attack (you have a chance to stun opponent) ")
if defend_attack=="defend":
我试图把
defend_attack=str(input("Would you like to defend (you only take a quarter of the damage) or attack (you have a chance to stun opponent) "))
但它仍然无法运作。我不断收到此错误消息
defend_attack=input("Would you like to defend (you only take a quarter of the damage) or attack (you have a chance to stun opponent) ")
TypeError: 'str' object is not callable
这是整个代码
import time
import random
next_line=input("Press Enter to Start\n")
time.sleep(1)
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
time.sleep(3)
print(" Myth of the Faded Warrior and the Cursed Blade ")
time.sleep(1)
print("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>")
print()
time.sleep(1)
user_name=input("Please enter your name: ")
difficulty=int(input("Please enter a difficulty:\n1 is easy\n2 is medium\n3
is hard\n4 is insane\n"))
print()
print("Hello "+user_name+" and welcome to your journey!")
next_line=input("Press enter after each line to continue on ")
print()
print("--------------------------------------------------------------")
print()
next_line=input("Your world used to be happy and full of life ")
next_line=input("The men, who go out to hunt their dinner for the night ")
next_line=input("The women, who stay at home and do the cleaning ")
next_line=input("And the children, who didn't have a worry in the world and
just played all day ")
next_line=input("There were many tales of a warrior who drove himself crazy
trying to get revenge on his nemesis ")
next_line=input("He finally found his nemesis and stabbed him in the back ")
next_line=input("He killed him with no honour ")
next_line=input("After his nemesis' death, the Gods put a curse on his blade
and banished him from the Earth ")
next_line=input("Before he faded away he promised that he would come back
and wreak havoc on the Gods ")
next_line=input("He did just that ")
next_line=input("He came back for revenge on the Gods")
next_line=input("It was not easy as those who wanted immense power seeked
the Faded Warrior and tried to kill him ")
next_line=input("One succeeded and inherited the power of the Cursed Blade
")
next_line=input("Those who inherited the Cursed Sword had the power to cut
mountains in half ")
next_line=input("They had the power to fuse the soul of those they had
killed to give them more power ")
next_line=input("They had the power to defeat the Gods if they were skilled
enough ")
next_line=input("However the curse meant that those who inherit the blade,
die after 3 months ")
next_line=input("The only way to relieve the curse was to kill the Gods ")
print()
print("---------------------------------------------------------------------
------------------------------------------")
print()
next_line=input("You are the next Faded Warrior ")
next_line=input("You kill the last Faded Warrior and pick up the Cursed
Blade ")
next_line=input("You feel the power of a thousand souls run through your
veins ")
next_line=input("The screams of a thousand souls rips a hole into the earth
and monsters from the Underworld burst out ")
next_line=input("The monsters desperse and go into hiding ")
next_line=input("They seek only of your Cursed Blade ")
next_line=input("You hear voices saying to head to Shadowkeep ")
next_line=input("You know where this is all you have to do is head down the
road ")
print()
if input("Do you want to head down the road to Shadowkeep? ")=="yes":
next_line=input("You begin to go down the cobble road to Shadowkeep ")
else:
next_line=input("I think you need to head down to Shadowkeep ")
print()
next_line=input("As you go down the cobble road you are startled by a Lycan
")
health=100
next_line=input=("The Lycan seems ready to attack ")
while True:
defend_attack=input("Would you like to defend (you only take a quarter
of the damage) or attack (you have a chance to stun opponent) ")
if defend_attack=="defend":
monster_hit=(random.randint(1,25)*difficulty//4)
health=health-monster_hit
next_line=input("You took "+str(monster_hit)+" damage ")
next_line=input("You now have "+str(health)+" health ")
else:
monster_health=30*difficulty
player_hit=random.randint(1,55)
monster_health=monster_health-player_hit
if monster_health<=0:
next_line=input("You killed the Lycan ")
break
else:
next_line=input("You hit the monster with "+str(player_hit)+"
damage ")
next_line=input("The monster now has "+str(monster_health)+"
health ")
答案 0 :(得分:1)
完整代码发布后:
next_line=input=("The Lycan seems ready to attack ")
输入后你有一个额外的符号
答案 1 :(得分:0)
如果您使用的是python3: 您很可能用另一个变量覆盖输入方法。将任何名为input的变量更改为其他内容并重试!