In code challenges: Functions, number 2 is Tip. I’m able to get the 2.5 like it wants but not the 0. Below is my code and of course I get a syntax error when dividing by 0, but I can’t figure out how to get the answer it wants. When I divide total / percentage I get 0.4 and 0.
# Write your tip function here: def tip(total, percentage): return percentage / total # Uncomment these function calls to test your tip function: print(tip(10, 25)) # should print 2.5 print(tip(0, 100)) # should print 0.0
This is what I get when I run that code:
Traceback (most recent call last):
File “script.py”, line 7, in
File “script.py”, line 3, in tip
return percentage / total
ZeroDivisionError: division by zero