If statement 关于折扣的if声明
数量If statement 关于折扣的if声明,if-statement,If Statement,数量 A_quantity = 10 B_quantity = 20 输入的费用 N = float (input('please enter the quantity of package: ')) X_total = float (N*99.00) 总投入折扣 Q_discount = (0.2*X_total) W_discount = (X_total*0.3) 费用加上折扣 Y_total = (X_total-Q_discount) M_total = (X_total-W_d
A_quantity = 10
B_quantity = 20
输入的费用
N = float (input('please enter the quantity of package: '))
X_total = float (N*99.00)
总投入折扣
Q_discount = (0.2*X_total)
W_discount = (X_total*0.3)
费用加上折扣
Y_total = (X_total-Q_discount)
M_total = (X_total-W_discount)
结果应该是$792.00的10个套餐
和20套1380.00美元的套餐
然而,第二个语句也有20%的折扣,总计1549.00美元,当它应该只有30%的折扣时,我不知道它是哪种语言,但这是一个算法问题:你应该首先尝试最高的值,因为它现在的设计方式,如果N=30,你将始终输入“if”,而不是“else”,如果N=5,您将输入“else”,但其中的if 让我试试,虽然我不懂语言:
def main ():
if N >= A_quantity:
print ('the total cost is $', \
format (Y_total, ',.2f'))
else:
if N >= B_ quantity:
print ('the total cost is $', \
format (M_total, ',.2f'))
main ()
取产品价值除以100,再乘以折扣
Y_total = (X_total-Q_discount)
M_total = (X_total-W_discount)
然后得到这个结果和乘积subitrair的值
def main ():
if N >= B_quantity:
print ('the total cost is $', \
format (M_total, ',.2f'))
else:
if N >= A_quantity:
print ('the total cost is $', \
format (Y_total, ',.2f'))
main ()
您可以将if条件更改为 如果N>=A\u数量&&N 如果N>=B_数量
你可能想考虑用一个特定的编程语言来标记这个。SRY,但这是为了好玩,OMG的克里斯库珀LOL。