Nov-24-2022, 11:40 PM
(This post was last modified: Nov-25-2022, 08:34 AM by Yoriz.
Edit Reason: Added code tags
)
(Nov-24-2022, 09:30 AM)buran Wrote: Also, note thatprint()
returnsNone
so a line like this
dollars = print(float(d.lstrip("$")))will assignNone
to namedollars
and even if youreturn dollars
you still have a problem.
Check also What is the purpose of the return statement? How is it different from printing?
I see your point.
I tried a different approach and this time I get: "can't multiply sequence by non-int of type 'str' ".
I find it hard to understand how to get an output that is non string nor sequence.
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): return d.lstrip("$") int(d) def percent_to_float(p): return p.rstrip("%") int(p) main()