【发布时间】:2021-04-17 09:59:24
【问题描述】:
我正在编写代码来获取学生的平均成绩,但出现了错误。 这是我的一段代码出错:
scoreinput=input("Score lesson: ")
while True:
if scoreinput.isnumeric():
scoreinput=int(scoreinput)
if scoreinput > 20:
scoreinput = int(input("This number is too big. Try again: "))
elif scoreinput < 0:
scoreinput = int(input("This number is too low. Try again: "))
else:
print("please write number correctly...")
这是此代码的输出有错误:
Score lesson: 5
Traceback (most recent call last):
File "e:\TEST PYTHON\test3.py", line 3, in <module>
if scoreinput.isnumeric():
AttributeError: 'int' object has no attribute 'isnumeric
请帮助我。谢谢
【问题讨论】:
-
我无法重现此内容。可能的原因是您在 2.x 下运行代码,或者您在其他地方重新定义了
input。
标签: python if-statement integer do-while isnumeric