我得到一个错误在我的python代码你能帮我修复它吗?

  • 本文关键字:代码 python 错误 一个 python
  • 更新时间 :
  • 英文 :


我得到错误:

randint = randint(1, 2)
TypeError: 'int' object is not callable

这是我的代码。我不知道是什么原因导致了这种情况的发生,这是否与循环两次有关,因为它允许我回答第一个问题,然后失败:截图。

from random import randint
score = 0
print('nnnnyour score right now is ', score, 'if it drops below zero you lose')
def make_question(num, italian, answer):
global score
if randint == int(num):
a = input('nWhat does ' + str(italian) + ' mean? ')
if a == str(answer):
score += 1
print('ncorrect your score is: ', score)
else:
score -= 1
print('nincorrect your score is now: ', score)

while True:
randint = randint(1, 2)
make_question(1, 'ripetere', 'repeat')
make_question(2, 'puoi/potere ripetere', 'can you repeat that')

第一次:

randint = randint(1, 2)

randintrandom模块的函数,通话正常。然后你把它换成12,现在它就只剩下int了。为您生成的值使用不同的名称(例如,whichquestion = randint(1, 2)并将if randint == int(num):替换为if whichquestion == int(num):),这样您就不会丢弃您需要的函数的句柄。

最新更新