创建允许用户输入多个项目的销售列表

时间:2016-04-29 05:16:59

标签: python

我一直在为python中的班级做一个项目,我觉得无论我做什么都无法做到。我们应该创建一个程序,捕获3个项目,然后为每个项目捕获4位信息。又名:货号:x,数量:x,价格$ x,重量x磅。然后它应该打印出小计,运费和放大处理成本,税收总额和最终总额。我遇到的问题是我们不允许为每个项目创建变量,并且必须在循环中完成所有操作。无论我尝试过什么,我所能做的就是让所有内容打印出最后输入的数据。

到目前为止,这是我的代码:

def main():

    #Range of 3 so that user may enter 3 seperate items
    for i in range(3):

        #Grabs user input for item description and/or name
        strDescription = str(input("Enter description of item: "))

        #Grabs user input for price of item
        fltPrice = float(input("Enter price of item: $ "))

        #Grabs user input for quanitity of item
        intQuantity = int(input("Enter quantity of item: "))

        #Grabs user input for weight of item in pounds
        fltWeight = float(input("Enter weight of item in pounds: "))

        #Subtotal is equal to price times number of items purchased
        fltPriceSub = fltPrice*intQuantity

        #Shipping 25 cents per pound
        intShipping = (.25*fltWeight)

        #There is a base fee of $5 per order applied to shipping
        intBaseRate = 5

        #Tax is 9 cents per dollar
        fltTax = 0.09*fltPriceSub

        fltPriceSubTotal = fltPriceSub+fltPriceSub+fltPriceSub

        intShippingTotal = intShipping+intShipping+intShipping+intBaseRate

        fltTaxTotal = fltTax+fltTax+fltTax



        #Order total is the subtotal+shipping+tax added together
        fltOrderTotal = fltPriceSubTotal+intShippingTotal+fltTaxTotal


    print("You have purchased ", strDescription, "")
    print("Your subtotal is ", fltPriceSubTotal, "")
    print("Shipping and handling is ", intShippingTotal, "")
    print("The tax is ", fltTaxTotal, "")
    print("The order total is ",fltOrderTotal, "")



main()

如果有人能指引我走向正确的方向,我会非常感激。

0 个答案:

没有答案