Reputation: 11
I am getting the error:
randint = randint(1, 2)
TypeError: 'int' object is not callable
This is my code. I have no idea what caused this to happen, is it something to do with going over the loop twice, because it allows me to answer the first question then fails: screenshot.
from random import randint
score = 0
print('\n\n\n\nyour 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')
Upvotes: 1
Views: 41
Reputation: 155323
The first time you do:
randint = randint(1, 2)
randint
is the function from the random
module, and the call works. Then you replace it with either 1
or 2
, and now it's just an int
. Use a different name for the value you're generating (say, whichquestion = randint(1, 2)
and replace if randint == int(num):
with if whichquestion == int(num):
), so you don't discard your handle to the function you need.
Upvotes: 1