Hi this is simple code it returns sum of a and b and asks user for input. this is for competitive programming website for example code forces but its not codeforces website.
Iam getting this dumb error i dont know why Ther error
my code
a= int(input())
b= int(input())
sum= int(a)+ int(b)
print(sum)
can anyone tell why iam getting this error
As I mentioned in the comment, input()
returns the entire line. You must split it by spaces to get ['3','2']
and then convert those to integers.
One way to do that would be
line = input().split()
a,b = int(line[0]), int(line[1])
Or if you're into one liners,
a,b = map(int, input().split())
Your code might have been formatted improperly and the int() isnt needed. I fixed your code for you :)
#Gather integers
a = int(input())
b = int(input())
sum = a + b #Create sum of 2 numbers
print(sum) #Print that sum
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.