-1
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)

折扣的费用

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 ()

结果应该是 792.00 美元的 10 个包

和 20 个套餐,售价 1,380.00 美元

然而第二条语句获得了 20% 的折扣,总计 1549.00 美元,而它应该只获得 30% 的折扣

4

3 回答 3

0

我不知道它是哪种语言,但这是一个算法问题:您应该首先尝试最高值,因为它现在的设计方式,如果 N = 30 ,您将始终输入 "if" ,而不是 "else " ,如果 N=5 ,你会输入 "else" ,但是里面的 if...

让我试试,虽然我不懂语言:

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 ()
于 2013-03-20T14:25:31.403 回答
0

将产品价值除以 100 再乘以折扣

然后得到这个结果和产品 subitrair 的值

var SomaPercent = ValorUnit/100 * descont;

var result_fim = ValorUnit-SomaPercent;
于 2013-03-20T14:26:08.613 回答
0

you can change the if condition to

if N >= A_quantity && N < B_quantity ...

if N >= B_quantity

..

于 2013-03-20T14:33:04.273 回答