Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

some issue with values im not quite understanding

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading