some issue with values im not quite understanding

Advertisements
def main():
    dollars = dollars_to_float(input("How much was the meal? "))

    percent = percent_to_float(input("What percentage would you like to tip? "))

    tip =  ((dollars * percent) /100)


    print(f"Leave ${tip:.2f}")

def dollars_to_float(dollars):
       dollars_to_float = float(dollars)

def percent_to_float(percent):
       percent_to_float = float(percent)


main()

so it seems like tip its not getting the values from dollars and percent but why?

>Solution :

In order for this to work, you must use return at the end of functions:

def foo(bar):
    return bar

print(foo("Hello")) # Prints "hello"

return makes functions output the value after return, in this case, the value of bar.

In your case, you add the return like so:

def dollars_to_float(dollars):
       dollars_to_float = float(dollars)
       return dollars_to_float

def percent_to_float(percent):
       percent_to_float = float(percent)
       return percent_to_float

Leave a ReplyCancel reply