-1
x = input("Enter the first number!")
y = input("Enter the second number!")
z = input("Enter the third number!")

def adding(a, b, c):
    s = a+b+c
    return s

c = adding(x, y, z)
print(c)

I've tried a program of addition in python IDE, but instead of printing sum it returns concatenation of numbers as strings.

I don't know what's wrong with it?

Anybody have any idea?

Sorry! for a dumb question.....

Gaurav Tomer
  • 661
  • 1
  • 9
  • 25
  • possible duplicate of [How can I read inputs as integers in Python?](http://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers-in-python) – TigerhawkT3 Jul 31 '15 at 04:32
  • You just need to cast your input to an integer. Use `int(input("Enter your number!"))`, though this won't handle errors. – fallaciousreasoning Jul 31 '15 at 04:52

2 Answers2

6

input by default should get the characters of type string. You need to convert them to integers. If those are floating point numbers, then change int in the below code to float.

def adding(a, b, c):
    s = int(a)+int(b)+int(c)
    return s
Avinash Raj
  • 166,785
  • 24
  • 204
  • 249
3

Your problem is that your input is in a string form and you need it to be in an int (or float) form.

def input_number(message):
    return int(input(message))

x = input_number("Enter the first number!")
y = input_number("Enter the second number!")
z = input_number("Enter the third number!")

def adding(a, b, c):
    s = a+b+c
    return s

c = adding(x, y, z)
print(c)

Should work nicely for you.

Note: This won't handle errors (say, if the user enters something that isn't a number). If you want your numbers to have decimals simply change the int in input_number to a float.