批發禽蛋公司立足於卵的數量它們的價格購買:規劃決策結構
0直到但不包括4打$ 0.50每打4直到但不包括6打$ 0.45每打6直到但不包括11打打擊每打0.40打11打打打0.35打每打額外雞蛋打價格爲每打價格的1/12
創建一個程序,提示用戶雞蛋的數量,然後計算帳單。該應用程序的輸出應該類似於:輸入購買的雞蛋數量:18該法案等於:$ 0.75
這是問題,這裏是我的代碼:
eggs = int(raw_input("Please enter the amount of eggs you have."))
if (eggs >=12 and eggs <=47):
dozen = int(eggs) // 12
dozenprice = float(dozen) * 0.50
extra = float(eggs) % 12
extraprice = float(extra)*((1/12)*0.50)
total = float(dozenprice) + float(extraprice)
print "Your total is " + str(total)
if (eggs >=48 and eggs<=71):
dozen = int(eggs) // 12
dozenprice = float(dozen) * 0.45
extra = float(eggs) % 12
extraprice = float(extra)*((1/12)*0.45)
total = float(dozenprice) + int(extraprice)
print "Your total is " + str(total)
if (eggs >=72 and eggs <=131):
dozen = int(eggs) // 12
dozenprice = float(dozen) * 0.40
extra = float(eggs) % 12
extraprice = float(extra)*((1/12)*0.40)
total = float(dozenprice) + int(extraprice)
print "Your total is " + str(total)
if (eggs >=132):
dozen = int(eggs) // 12
dozenprice = float(dozen) * 0.35
extra = float(eggs) % 12
extraprice = float(extra)*((1/12)*0.35)
total = float(dozenprice) + int(extraprice)
print "Your total is " + str(total)
爲什麼ISN」 t出現額外雞蛋的價格?
Python中的空白問題非常重要,這在語法上不是有效的。 – jonrsharpe
@CliffBurton粘貼的代碼格式不正確。對Python2.7如何解釋'/'正常劃分有一個合理的誤解,但從問題不清楚是這個問題。 – TemporalWolf