python - 求解购买算法程序
问题描述
所以,我现在被困住了。
如果购买了多个或单个物品,我正在创建一个程序来计算完整的销售额。该程序还应该计算购买的折扣门槛和州销售税。我可以让程序运行,但是,尽管输入了条目,我的最终结果是 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.")
解决方案
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?"))
推荐阅读
- powerbi - 按列计算持续时间
- mysql - MySQL - 插入时以前缀作为主键的自动增量
- ionic-framework - 如何在ionic 3中更改启动画面上的微调器
- python - 查找数据框的累积回报
- hibernate - Apache Phoenix 的 Spring 数据源
- java - 为项目、项目阶段和阶段模板保持状态(TO_DO、IN_PROGRESS、DONE)的最佳方式是什么
- angular - 垫旋转器未显示
- javascript - 用于 jquery 的 Play 商店应用程序详细信息
- alibaba-cloud - 我们如何使用自定义 SQL 从外部数据库中将数据拉到阿里巴巴 Quick BI 中?
- c# - 将数据从命令行传送到 C# 控制台应用程序