![](/img/trans.png)
[英]Traceback (most recent call last): File "main.py", line 12, in <module> for error in authorisation: TypeError: 'bool' object is not iterable
[英]Getting error message Traceback (most recent call last): File "input/code.py", line 1, in <module> a= int(input())
嗨,这是一个简单的代码,它返回 a 和 b 的总和并要求用户输入。 这是用于竞争性编程网站,例如代码力量,但不是代码力量网站。
我收到这个愚蠢的错误我不知道为什么Ther 错误
我的代码
a= int(input())
b= int(input())
sum= int(a)+ int(b)
print(sum)
谁能告诉我为什么我收到这个错误
正如我在评论中提到的, input()
返回整行。 你必须用空格分割它以获得['3','2']
然后将它们转换为整数。
一种方法是
line = input().split()
a,b = int(line[0]), int(line[1])
或者如果你喜欢一个班轮,
a,b = map(int, input().split())
您的代码可能格式不正确,不需要 int()。 我为你修复了你的代码:)
#Gather integers
a = int(input())
b = int(input())
sum = a + b #Create sum of 2 numbers
print(sum) #Print that sum
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.