作业:销售税python程序

2024-06-17 11:00:18 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我被要求使用这个代码:

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

我还必须使用for循环。 我必须给用户3个提示:销售价格,起始价,结束价。然后,程序将向用户提供费率和总价表:

我在for循环和合并while语句时遇到了麻烦

我正处于一个非常开始的过程:

^{pr2}$

Tags: or代码用户程序forinput选项整数
1条回答
网友
1楼 · 发布于 2024-06-17 11:00:18

像这样?在

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")

输出:

^{pr2}$

相关问题 更多 >