2017-01-07 40 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

相關問題