Skip to content
Advertisement

Python – sum of two numbers program error [duplicate]

I was just getting into Python programming. I wrote a simple program to calculate sum of two user-input numbers:

JavaScript

Now if I enter the numbers as 23 and 52, what showed in the output is:

JavaScript

What is wrong with my code?

Advertisement

Answer

input() in Python 3 returns a string; you need to convert the input values to integers with int() before you can add them:

JavaScript

(You may want to wrap this in a try:/except ValueError: for nicer response when the user doesn’t enter an integer.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement