当我输入我的简单代码时:
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
编辑:
_>>> times = int(input("How many times do I have to tell you? "))
How many times do I have to tell you?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: ''
>>> for i in range(times):
... print("Clean your room!")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'times' is not defined
>>> input("2")
2
''
>>> _我想我的.bashrc和.bash_profile出了点问题。
发布于 2019-11-28 16:11:43
您好,因为错误告诉您:
TypeError: 'str' object cannot be interpreted as an integer首先你在第一行输入字符串,在第二行输入一个int。
我再检查一次,我可以告诉你这两个版本都是100%有效的:
times = input("How many times do I have to tell you? ")
times = int(times)
for i in range(times):
print("Clean your room!")
times = int(input("How many times do I have to tell you? "))
for i in range(times):
print("Clean your room!")
input("")我在最后添加了input(""),这样控制台就可以一直打开
如果这仍然不起作用,我们需要寻找其他地方。但我相信我们会想出办法的。
https://stackoverflow.com/questions/59084229
复制相似问题