#๐ Help with funcs
15 messages ยท Page 1 of 1 (latest)
@wet wren
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
#preform task function
def addnum(num1, num2):
print (int(num1 + num2))
def subtract(num1, num2):
print (int(num1 - num2))
def multiply(num1, num2):
print (int(num1 * num2))
def divide(num1, num2):
print (int(num1 / num2))
num1 = float(input("num1"))
num2 = float(input("num2"))
ad = addnum(num1, num2) #calling the function
print(ad) # returns none since there is not a return
minus = subtract(num1, num2)
print(minus)
x = multiply(num1, num2)
print(x)
div = divide(num1, num2)
print(div)
#returns a value function
def addnum(num1, num2):
return (int(num1 + num2))
def subtract(num1, num2):
return (int(num1 - num2))
def multiply(num1, num2):
return (int(num1 * num2))
def divide(num1, num2):
return (int(num1 / num2))
num1 = float(input("num1"))
num2 = float(input("num2"))
ad = addnum(num1, num2) #not calling because it is a return function
minus = subtract(num1, num2)
x = multiply(num1, num2)
div = divide(num1, num2)
print(ad) # returns the value
print(minus) # can also use print(subtract(num1, num2))
print(x)
print(div)
According to the notes
Am i understanding how functions work correctly?
i mean it looks like it
i'd also just want to point out two things:
- you don't need brackets for a
returnstatement - opt for 4 spaces since that's "normal" indentation
I don't know why you define the functions twice
They don't get "used up" when you call them
I think you're confused by the definition of "return" and "print"
@wet wren
ad = addnum(num1, num2) #not calling because it is a return function
This is calling the function and the value gets returned to ad. It doesn't print to the console, it just stores the value in a variable
print(ad) # returns the value
Nothing is "return"ed here. Print just displays the value in ad on the console
don't reuse function names in the same scope, it will redefine the function and is something you want to avoid
So i remember the difference
Ye i just did that so i know the difference
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.