Python Forum

Full Version: help with function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Yes, but what is your question (I'm guessing it is that you are printing None)?
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)