我看过其他相同主题/问题的主题,但这些解决方案都不适用于我。
我收到错误:TypeError:' str'对象不可调用
在以下代码中尝试执行shoot = play(fk,int(uCard),int(b))时。我试着打电话给'功能'玩'传递3个值(布尔值和2个int)并希望返回一个字符串值:
field=[[0,0,0],[0,0,0],[0]]
def play(fk1,uCard1,b1):
shoot1=''
a=0
while a<(len(field)-1):
if field[a][b1]<uCard1:
print('you beat player '+str(field[a][b1]))
field[a][b1]=0
shoot1='True'
else:
if fk1==False:
uCard=0
print('player '+str(field[a][b1])+' beat you. attack ends.')
field[a][b1]=0
shoot1='False'
break
else:
print('Your FK beats player '+str(field[a][b1]))
fk1=False
field[a][b1]=0
shoot1='True'
a=a+1
return shoot1
#MAIN BEGINS HERE
fk=False
shoot='False'
b=1
uCard=random.randint(1, 10)
if uCard==1:
print('FOUL!... you drew an indirect free kick...')
fk=True
uCard=random.randint(1, 10)
shoot=play(fk,int(uCard),int(b))
else:
shoot=play(fk,int(uCard),int(b))