Converting '5%' into actual 5%

244 views Asked by At

not sure how many things I'm doing wrong here, I get "could not convert string to float: '5%'. Code is below, any insights appreciated.... many thanks.

tip=input("How much would you like to tip on your US$88.5 cheque, 5%, 12.5%?")

cheque = 88.5

total= cheque*(float(tip)+1)

print("Thank you, the total will be total $%.2f" % (total))
1

There are 1 answers

3
devondre On

This works when you enter percentage. Works with 5% or 5, too.

tip=raw_input("How much would you like to tip on your US$88.5 cheque, 5%, 12.5%?").rstrip("%")

cheque = 88.5

total = cheque*(float(tip)/100)+cheque

print("Thank you, the total will be total $%.2f" % (total))