Skip to content
Sign upLog in
← Back to Community

Please Help Me, I Guess It’s Simple

Profile icon
PizzaMan21

How would I add a function with a “return” value in it? Where would I put it if there was?

For example:

def reprompt():
answer = float(input("Number can't be less than or equal to zero, try again: "))
return answer

Voters
Profile icon
PizzaMan21
Comments
hotnewtop
Profile icon
btfuss

Return Function()

def reprompt(): answer = float(input("Number can't be less than or equal to zero, try again: ")) return answer
Lets say this is your function. All you need to do is to is take a variable from the return value:
output = str(reprompt())

Profile icon
PizzaMan21

@2plus2is4hoi
this is what I am supposed to do:

Create at least two functions that are called inside the main portion of your program. At least one function should “return” a value.

I already did the first part, it’s just I’m confused on where I’m going to place the return value, cus I don’t see where I could put one.

It doesn’t matter if there are three, I was going to make three anyways for one with the “return” value in it.

Profile icon
Coder100

return values are usually placed at the end of functions.

@KeenanBusch

Profile icon
btfuss

@KeenanBusch

well you need to return a value right.

rules of a return value:

-only 1 in a function as it ends the function
-has to be at the end of a function (in most cases)

also what you could do is:
lololol = int(0)
def im_lol():
lololol = int(1)

im_lol()
that would change the value outward.
what you should do is what you have already done.
just add a return value at the end of your function

Profile icon
Muffinlavania

Your code seems to work, high() and low() will both return your input answer.
That should just work lol

Profile icon
RYANTADIPARTHI

Solution

functions actually do use return statements. Try this.

def sayhello(): return "Hello" print(sayhello())

with parameters

def withpars(a, b): return a + b print(withpars(2, 2))

like that.
That should work

Profile icon
Coder100

The return value is the output you can utilize for later use. For example, the input() function returns what the user typed in.

Here is an example

def add(a, b): return a + b print(add(1, 3))