2016-05-28 17 views
1

私は、ユーザーに注文の金額と重量の両方を入力し、送料を表示するように計算するプログラムを作成しようとしています。if、elif、else ifが真でないときに問題が発生するスキップ

オンライン注文の送料は、ご注文金額と配送重量に基づいています。 $ 100 +配送料はなく、配送料は$ 100未満です。送料は 40ポンド以上:$ 1.09 /ポンド 20ポンド以上:ポンド当たり0.99円 20ポンド以下:$ 0.89 /ポンド

注文額が$ 100 +の場合、重量は無関係であり、あなたのプログラムはそれを求めてはなりません。

は、これまでのところ、これは私が持っているものです。

#Have user enter weight of order 
weight = int(input('Enter the weight of your order:')) 

#Determine shipping cost 
if weight >= 40: 
    total = weight * 1.09 
elif weight >= 20: 
    total = weight * 0.99 
elif weight <=20: 
    total = weight * 0.89 

#does shipping apply 
if total >= 100.00 
    else: 
if total <= 100.00 

私はここから行くし、出荷が適用されないの下に他の文字列に何をどこに置くかわからないことです。

答えて

1

else、ただprintを使用しないでください。または、これを使用することができます:

if total >= 100.00: 
    print() 
else: 
+0

かっこ内に何も置かないと、自動的に次のものにスキップされますか?もしそうなら、ここに質問する方法はありますか? – mrsga16eats

1

注文の値をチェックすることから始めてください。あなたが言ったように、それが100ドル以上であれば、それはとにかく送料無料だから重量は重要ではありません。あなたはすでにあなたのプログラムのどこか他のところからその番号を持っているでしょうから、値をチェックしてください。その後、必要に応じて体重を確認することができます。

# value is defined earlier in the program, and contains the total cost of the purchase 
if value >= 100: 
    print "You quality for free shipping!" 
else: 
    weight = int(input("Enter the weight of your order: ")) 
    # Now determine shipping cost 
    if weight > 40: 
     total = weight * 1.09 
    elif weight > 20: 
     total = weight * 0.99 
    else: # because there should only be weights equal to or below 20 remaining 
     total = weight * 0.89 

これで、ユーザーに合計を提示したり、必要なことを行うことができます。

関連する問題