我需要计算书籍的总购买价格。折扣取决于购买的书籍数量。这些被分成if语句。我如何让我的代码充分发挥作用?我目前收到此错误信息:如何从if语句中扣除折扣率
这里是我的代码:
BOOK_PRICE = 100
def main():
numBooks = int(input("Enter the number of books you will be purchasing: "))
discountPrice(numBooks)
subTotalPrice(numBooks)
#I have a problem getting the returned subTotal price
totalPrice(theSubTotalPrice,discountRate)
def subTotalPrice (numBooks):
theSubTotalPrice = numBooks * BOOK_PRICE
print("Your subTotal is: $ ",theSubTotalPrice)
return theSubTotalPrice
def totalPrice (theSubTotalPrice):
theTotalPrice = theSubTotalPrice * discountRate
print("Your Total Price is: $ ", theTotalPrice)
def discountPrice (numBooks):
if numBooks <= 0 and numBooks <= 9:
print(" ")
discountRate = .00
return discountRate
if numBooks >= 10 and numBooks <= 19:
print("Since you are ordering",numBooks,"books you will receive a 20% discount!")
#how do any of these discountRates get put back to call them in a different module?
discountRate = .20
return discountRate
if numBooks >= 20 and numBooks <= 49:
print("Since you are ordering",numBooks,"books you will receive a 30% discount!")
discountRate = .30
return discountRate
if numBooks >= 50 and numBooks <= 99:
print("Since you are ordering",numBooks,"books you will receive a 40% discount!")
discountRate = .40
return discountRate
if numBooks >= 100:
print("Since you are ordering",numBooks,"books you will receive a 50% discount!")
discountRate = .50
return discountRate
main()
我很好奇:是不是更多的工作来发布截图那么这将是粘贴文本? ;) – zvone
不是,剪切工具需要几秒钟! – Alina
我看到:)但文字更好。它在各种显示器上看起来更好,可以搜索内容,复制和粘贴作品,占用更少的存储空间和带宽......你应该粘贴文本;) – zvone