我正在用python做一个基本的游戏,我试图在一个不同的函数中调用一个全局变量。 这是我收到的错误消息:
File "C:\ARENA\Arena.py", line 154, in <module>
gamea()
File "C:\ARENA\Arena.py", line 122, in gamea
if age1 > age2():
TypeError: 'str' object is not callable
我对Python还是个新手,所以我不知道怎么了。这是我想修改的代码部分
#character Titles Player1
def char1Title():
print ("Player 1")
print()
global myName1
myName1 = input("Whom might you be?")
print()
global age1
age1 = input("What is your age?")
#2 player gameplay code
def gamea():
attack = input('Enter to start BATTLE!!!!')
**#here's where I try to call "age1" again:**
if age1 > age2():
print(myName)
print("WINS!!")
elif age2 > age1():
print(myName2)
print("WINS!!")
调用字符串时,不要在结尾处加括号,否则python会认为它是一个函数:
这是您编辑的代码:
另外,您不会在任何地方调用
age2
,因此请确保调用。相关问题 更多 >
编程相关推荐