Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with function
#1
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
Reply
#2
Yes, but what is your question (I'm guessing it is that you are printing None)?
Reply
#3
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)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020