作业:销售税 python 计划

Homework: Sales Tax python program

我正在 Python 做作业。我正在尝试创建一个计算销售税的程序。我需要给用户一个选项来设置要计算的开始汇率和要计算的结束汇率。然后该程序将计算开始和结束之间的所有整数(例如,开始 =5%,结束 = 8%,它将计算 5,6,7,8 % 税。

有人要求我使用此代码:

while begin <= 0 or begin > 10:
    begin = int(input("Enter tax rate: "))

我还必须使用 for 循环。 我必须给用户 3 个提示:销售价格、开始价格、结束价格。然后,该程序将为用户提供 table 的费率和总价:

我对 for 循环和合并 while 语句感到困惑

我正处于以下过程的最开始阶段:

productprice = float(input("Enter the product price: "))
begin = float(input("Enter tax rate: "))

total = productprice + productprice * begin/100
print total
raw_input ("Enter to exit")

像这样?

price = float(input("Enter the product price: "))

# declare begin and end variables as empty strings to start
begin = ""
end = ""

# the while loops are to make sure the user inputs a tax rate that 
# is more than 0 and less than 10
while begin <= 0 or begin > 10:
    begin = int(input("Enter tax rate: "))

while end <= 0 or end > 10:
    end = int(input("Enter end tax rate: "))    

# does the math for every integer between beginning and end, prints a 'table'   
for x in range(begin,end+1):
    total = price + price * x/100
    print "Price: "+str(price)+"\tTax: "+str(x)+"\tTotal: "+str(total)
    x += 1


raw_input ("Enter to exit")

输出:

Enter the product price: 100
Enter tax rate: 6
Enter end tax rate: 9
Price: 100.0    Tax: 6  Total: 106.0
Price: 100.0    Tax: 7  Total: 107.0
Price: 100.0    Tax: 8  Total: 108.0
Price: 100.0    Tax: 9  Total: 109.0
Enter to exit