【问题标题】:Homework: Sales Tax python program作业:销售税python程序
【发布时间】:2015-03-18 00:30:01
【问题描述】:

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

我被要求使用此代码:

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

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

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

【问题讨论】:

    标签: python for-loop


    【解决方案1】:

    像这样?

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-28
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2014-06-26
      • 1970-01-01
      相关资源
      最近更新 更多