现在我正在计算以下条目的总数。如果我不给一个输入,我希望它认为输入为零,但是如果没有输入,就没有总的计算。一个简单的变量==''检测
#getting the quantity of fries etc
coF=float(Fries.get()) #cost of fries
coD=float(Drinks.get())
coFilet=float(Filet.get())
coBurger=float(Burger.get())
coChicken=float(Chicken_Burger.get())
coCheese=float(Cheese_Burger.get())
#computation
costofFries=coF * 300 #store whatever is entered in widget
costofDrinks=coD * 300
costofFilet=coFilet * 200
costofBurger=coBurger * 100
costofChicken=coChicken * 150
costofCheese=coCheese * 100
#total calculation
paytax=((costofFries+costofDrinks+costofFilet+costofBurger+costofChicken
+costofCheese)*0.2)
TotalCost=(costofFries+costofDrinks+costofFilet+costofBurger+costofChicken
+costofCheese)
Ser_Charge=((costofFries+costofDrinks+costofFilet+costofBurger+costofChicken
+costofCheese)/99)
现在,如果我输入所有的值,那么我就得到正确计算的总数,如果我不输入值,它就计算总数。请建议
你能做到的
或与if/else一起使用特殊结构
但是有人可以放置文本或不正确的浮点,所以最好使用
try/except
来捕获它相关问题 更多 >
编程相关推荐