2017-01-07 41 views
-1

不确定有多少事情我在这里做错了,我得到“无法将字符串转换为浮点数:'5%' 代码在下面,任何见解都被赞赏...当你输入的百分比,如果你进入完全合理价值'5%'。非常感谢。将“5%”转换为实际的5%

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)) 

回答

0

这工作。 厂用5%或5,太。

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)) 
+1

不是的。在这些问题的答案重复做的地址。 – usr2564301

+0

@RadLexus我现在修复了代码 –

+0

它仍然是重复的,所以你最好在那里接听。 (目前还没有答案使用'rstrip',*技术上*使用'strip'的错误是因为它们允许'%5'作为有效输入。) – usr2564301

相关问题