Python Forum
help with function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: help with function (/thread-2874.html)



help with function - meggy - Apr-17-2017

Hi, I'm new with using python and I need a help. I´m trying to write a code for sum function. A user input 2 numbers and answer is a sum of them. I wrote this:
def suma(a,b):

   print(a+b)

x=int(input('the first number'))
y=int(input('the second number'))
print(suma(x,y))
Thanks for help


RE: help with function - Mekire - Apr-17-2017

Yes, but what is your question (I'm guessing it is that you are printing None)?


RE: help with function - wavic - Apr-17-2017

Well, your function prints the sum of the two arguments but after that, the function returns None which print() is printing. A function returns None if you don't specify something else.
You can just call the function or to return the sum

Returning the sum
x=int(input('the first number'))
y=int(input('the second number'))

def suma(a,b):
 
   return a+b

print(suma(x, y))
Just call the function.

x=int(input('the first number'))
y=int(input('the second number'))

def suma(a,b):
 
   print(a+b)

suma(x , y)