当我输入简单的代码时:
times = input("How many times do I have to tell you? ")
times = int(times)
for i in range(times):
print("Clean your room!")
我收到以下错误消息:
>>> times = input("How many times do I have to tell you? ")
How many times do I have to tell you? times = int(times)
>>>
>>> for time in range(times):
... print("Clean your room!")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer
>>>
我正在使用python 3.8
您好,因为错误告诉您:
TypeError: 'str' object cannot be interpreted as an integer
首先您要在第1行中添加字符串。在第2行中,您需要对一个int进行设置。
因此更改第一行:
question = input("How many times do I have to tell you? ")