2017-12-07 19 views
-4
# Tipper Program 
# User enters the bill total and the program computes two amounts, 
# a 15 percent tip and a 20 percent tip 

print("\t\t\t ** ** ** ** ** ** ** ** ** **") 

print("\n\t\t\t\t Tip Calculator") 

print("\n\t\t\t ** ** ** ** ** ** ** ** ** **") 

bill = input("\nPlease enter your restaurant's bill total: ") 

tip_15 = bill * 0.15 

tip_20 = bill * 0.20 

float(print("\n\nA 15% tip for this bill comes out to ", tip_15)) 
float(print("\nA 20% tip for this bill comes out to ", tip_20)) 


input("\n\nPress the enter key to exit.") 

請求書の合計数を入力してもアプリは終了します。この問題を解決するための推奨事項はありますか?このプログラムの実行に問題があります

+2

あなたはprint文をfloatにキャストしていますか?最後の2行目と3行目から 'float()'を削除してください – AK47

+0

一般的なヒント: 'cmd.exe'(Windowsを想定)からプログラムを実行してください。ダブルクリックするだけでエラーが発生するとすぐに終了し、エラーメッセージを読むことができなくなります。 – Blorgbeard

+0

@Blorgbeard:最後に 'input(" \ n \ n終了するにはEnterキーを押してください。) 'しませんでしたか? – martineau

答えて

3

あなたが入力をユーザーに求める場合は、あなたが0.15と0.20

bill = float(input("\nPlease enter your restaurant's bill total: ")) 

を掛け前にfloatにこの値をキャストする必要があり、また、あなたの最後の2行はフロート

にキャストすべきではありません
print("\n\nA 15% tip for this bill comes out to: ", tip_15) 
print("\nA 20% tip for this bill comes out to: ", tip_20) 
+0

おそらくしたい: print( "\ n \ nこの請求書のための15%のヒント" .format(tip_15)) –

関連する問題