#๐Ÿ”’ Help with funcs

15 messages ยท Page 1 of 1 (latest)

low voidBOT
#

@wet wren

Python help channel opened

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.

wet wren
#
#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?

manic gorge
#

i'd also just want to point out two things:

  1. you don't need brackets for a return statement
  2. opt for 4 spaces since that's "normal" indentation
tough crane
#

I don't know why you define the functions twice

#

They don't get "used up" when you call them

buoyant wharf
#

@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

sturdy lagoon
wet wren
wet wren
low voidBOT
#
Python help channel closed for inactivity

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.