【发布时间】:2020-02-25 23:50:53
【问题描述】:
有人可以帮我解决我的代码问题吗?最后通过代码的回复只是循环而不是完全重新开始程序会很棒有人可以帮助我谢谢,我知道它非常基本,也许不是最好的方法这样做,但只要它工作正常。
start = input("Do you want to make an order? ")
while start == "Y" or start == "y" :
title = input("Enter book title: ")
sPrice = float(input("Enter price of book: "))
voucher = input("Do you have a voucher? ")
while sPrice >0 :
amount = float(input("Enter amount of books: "))
while amount >= 1 and amount <= 80 :
if amount >= 5 and amount <= 10 :
disc = 5
elif amount >= 11 and amount <= 50 :
disc = 7.5
elif amount >= 51 and amount <= 80 :
disc = 10
else :
disc = 0
base = sPrice * amount
discVal = (base * disc) / 100
dPrice = base - discVal
if voucher == "Y" or voucher == "y" and dPrice >= 25 :
voucherValue = 25
else :
voucherValue = 0
fPrice = dPrice - voucherValue
print (f"Discount rate: {disc}%")
print (f"Discount value: £{discVal:.2f}")
print (f"Total before discount: £{base:.2f}")
print (f"Total after discount: £{dPrice:.2f}")
if voucher == "Y" or voucher == "y" and dPrice >= 25 :
print (f"Value of voucher: £{voucherValue:.2f}")
print (f"Final cost of order: £{fPrice:.2f}")
else :
print ("ERROR - Invalid amount!")
amount = float(input("Enter amount of books: "))
else :
print ("ERROR - Price too low!")
sPrice = float(input("Enter price of book: "))
else :
start = input("Do you want to make an order? ")
【问题讨论】:
-
我猜这是给学校的,你学过函数吗?
-
您需要在两个地方包含
if以验证输入值。将while sPrice >0 :更改为if sPrice >0 :并将while amount >= 1 and amount <= 80 :更改为if amount >= 1 and amount <= 80 : -
@chrisHG 是的,它是上学的,但我们要到下一个街区才能了解函数
-
@Ratnesh 试试看,谢谢
-
@Ratnesh 我认为现在已经解决了,谢谢
标签: python python-3.x