-1

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))
Maroun
  • 94,125
  • 30
  • 188
  • 241
Marie
  • 1

1 Answers1

0

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))
devondre
  • 493
  • 6
  • 14
  • 1
    Not if you enter the totally reasonable value `5%`. The answers in the duplicate do address that. – Jongware Jan 07 '17 at 10:16
  • @RadLexus I fixed the code now. – devondre Jan 07 '17 at 10:21
  • It's still a duplicate, so you are better off answering in there. (There is no answer yet that uses `rstrip`, and *technically* the ones using `strip` are wrong because they allow `%5` as valid input.) – Jongware Jan 07 '17 at 10:29