Nov-26-2022, 06:50 PM
(This post was last modified: Nov-26-2022, 08:33 PM by Yoriz.
Edit Reason: Added code tags
)
(Nov-25-2022, 06:34 AM)ndc85430 Wrote: Please can you post code within Python tags?
Remember that once a return statement is hit, execution goes back to the caller of the function. No code in the function after the return is executed.
Which editor are you using? Some of them give you warnings about things like this, so you notice.
First of all thank you! Can you elaborate? I tried many different things but cannot figure out how to take the input of the questions and return a float that is not 'NoneType'. For now I don't even try to eliminate the dollar and percent signs. The code and the error are attached below.
Code:
def main(): dollars = dollars_to_float(input("How much was the meal? ")) # Recall that input returns a str percent = percent_to_float(input("What percentage would you like to tip? ")) tip = dollars * percent print(f"Leave ${tip:.2f}") def dollars_to_float(d): float() def percent_to_float(p): float() main()The error:
Error:tip = dollars * percent
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'