Home > OS >  Getting error message Traceback (most recent call last): File "input/code.py", line 1, in
Getting error message Traceback (most recent call last): File "input/code.py", line 1, in

Time:11-02

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

CodePudding user response:

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())

CodePudding user response:

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
  • Related