首页 > 解决方案 > 求解购买算法程序

问题描述

所以,我现在被困住了。

如果购买了多个或单个物品,我正在创建一个程序来计算完整的销售额。该程序还应该计算购买的折扣门槛和州销售税。我可以让程序运行,但是,尽管输入了条目,我的最终结果是 0.0 美元。在这一点上,我可以确定它是将 SOMETHING 乘以 0,我认为这是税收输入,但我完全不知道如何纠正这个问题。下面是使用的代码。

#declarations
A_STATE_TAX = float(.056)
C_STATE_TAX = float(.029)
N_STATE_TAX = float(.05125)
U_STATE_TAX = float(.047)
state = ''
tax = float()
completeSale = ()
sockPrice = int(5)
sandalPrice = int(10)
shoePrice = int(20)
bootPrice = int(30)
quantityShoes = int()
quantitySocks = int()
quantityBoots = int()
quantitySandals = int()
quantityTotal = int()
quantityTotal = int(quantityTotal)
basePriceSocks = (quantitySocks * sockPrice)
basePriceShoes = (quantityShoes * shoePrice)
basePriceBoots = (quantityBoots * bootPrice)
basePriceSandals = (quantitySandals * sandalPrice)
baseTotal = int(basePriceSocks + basePriceShoes + basePriceBoots +basePriceSandals)
discount = float()
discountAnswer = (baseTotal * discount)
purchaseWithoutTax = baseTotal - (baseTotal * discount)
taxAnswer = purchaseWithoutTax * tax

#mainbody
print("This algorithm will calculate your purchase.")

#housekeeping()
print("How many shoes do you wish to purchase?")
input(quantityShoes)
print("How many socks?")
input(quantitySocks)
print("Boots?")
input(quantityBoots)
print("And sandals?")
input(quantitySandals)

#purchaseinfo()
quantityTotal = (quantityShoes + quantityShoes + quantityBoots + quantitySandals)
if quantityTotal < 6:
    discount = 0
elif quantityTotal > 6 and quanityTotal < 10:
    discount = .10
else:
    discount = .20
purchaseWithoutTax = baseTotal - (baseTotal * discount)

#stateTax()
print("Please choose the following state: Arizona, New Mexico, Colorado or Utah.")
input(str(state))
if state == "arizona":
      tax = A_STATE_TAX
elif state == "new mexico":
    tax = N_STATE_TAX
elif state == "colorado":
    tax = C_STATE_TAX
else:
    tax = U_STATE_TAX
completeSale = (purchaseWithoutTax * tax) - taxAnswer

#endOfJob()
print(format(completeSale, '.2f'))
print("Your total is ", format(completeSale, '.2f'), " dollars.")
print("Thank you for your patronage.")

标签: pythonsales-tax

解决方案


input()不像你使用它的方式工作。输入的参数input() 在用户输入之前打印。你做了相当于:

quantityShoes = int()
print("How many shoes do you wish to purchase?")
input(quantityShoes)

第一行设置quantityShoes等于默认整数,即 0。第二行打印该文本。第三行打印该数字并等待用户输入。你想做这样的事情:

quantityShoes = int(input("How many shoes do you wish to purchase?"))

推荐阅读