类型错误:int() 参数必须是字符串、类似字节的对象或实数,而不是“builtin_function_or_method”

问题描述 投票:0回答:1

我昨天写了这段Python代码,但我不知道我做错了什么。

这是代码:

import random
    score = 0
    number = 7
    for i in range (1,11):
        print('What is',i,'x',number)
        answer = input
        if answer == 'stop':
            break
        if answer == 'skip':
            continue
        right = i * number
        if int(answer) == right:
             print('right!')
            score = score + 10
        else:
            print('Wrong, it is',right)
    print('Wrong!')
    print('Your score is:',score)

我希望它成为一个为我妹妹学习乘法的程序。 该程序应该提出如下问题:3 x 7 是多少。您可以回答它,它会说明您是否正确。

python random input
1个回答
0
投票

input
是您需要调用才能获取用户输入的函数;您只需将函数
input
本身传递给
int()
函数。

answer = input()
# ...
if int(answer) == right:
    # ...
© www.soinside.com 2019 - 2023. All rights reserved.