Help

+1 Ricardo Gullo · December 29, 2014
Im trying to make a tip calculator function and im having an error.

percent1 = input("Percent of the bill:")
bill2 = input("How much money is the bill?:")

def tip_calculator(percent, bill):
tip = percent / 100 * bill
print(tip)

tip_calculator(percent1, bill2)

C:\Python32\python.exe "C:/Users/Richard/PycharmProjects/testcode/Testing Code.py"
Percent of the bill:15
How much money is the bill?:37.99
Traceback (most recent call last):
  File "C:/Users/Richard/PycharmProjects/testcode/Testing Code.py", line 8, in <module>
    tip_calculator(percent1, bill2)
  File "C:/Users/Richard/PycharmProjects/testcode/Testing Code.py", line 5, in tip_calculator
    tip = percent / 100 * bill
TypeError: unsupported operand type(s) for /: 'str' and 'int'

Process finished with exit code 1

Post a Reply

Replies

Oldest  Newest  Rating
0 Bernard Pyc0d333 Parah · December 29, 2014
hello Ricardo, your error seems to be indentation errors, and the percentage calculation was wrong.
you also needed to give a space before and after  the "/" in calculating the tip
Here is a version of your code. hope it works


percent1 = input("Percent of the bill:")
bill2 = input("How much money is the bill?:")

def tip_calculator(percent, bill):
    tip = bill / 100 * percent  #the way you did it was always going to tip 0
    print(tip)

tip_calculator(percent1, bill2)
  • 1

Python

107,334 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator