-1
該程序將詢問用戶單價和數量。然後它將單位價格乘以數量。如果數量大於10,可享受5%的折扣。如果數量大於100,可享受10%的折扣。如何創建一個while循環來詢問用戶是否要繼續,如果不是,它會中斷?
def bmth(unit, quan):
def computeN(unit, quan):
z = unit * quan
print(z)
if 10 <= quan < 99:
ordercost = unit * quan
discfive = ordercost * .05
v = ordercost - discfive
print('Your original price was ', ordercost)
print('You Saved', discfive, 'off')
print('Your new price is now ', v)
elif quan >= 100:
ordercost2 = unit * quan
discten = ordercost2 * .10
n = ordercost2 - discten
print('Your original price was ', ordercost2)
print('You save ', discten, 'off')
print('Your new price is now ', n)
else:
computeN(unit, quan)
while True:
unit = float(input('Enter the Unit price: '))
quan = int(input('Enter your items: '))
onelasttime = input('Do you wish to continue? Y or N: ')
Y = bmth(unit, quan)
if onelasttime:
input(Y)
elif onelasttime:
input(N)
break