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

Python 创建允许用户输入多个项目的销售列表,python,Python,我一直在用python为我的班级做一个项目,我觉得无论我做什么我都做不好。我们应该创建一个程序,捕获3个项目,然后为每个项目捕获4位信息。AKA:项目:x,数量:x,价格$x,重量x磅。然后,它应该打印小计、运输和处理成本、税收总额和最终总额。我遇到的问题是,我们不允许为每个项创建变量,必须在循环中完成所有操作。不管我做了什么,我能做的就是把最后输入的数据打印出来 以下是我目前的代码: def main(): #Range of 3 so that user may enter 3 s

我一直在用python为我的班级做一个项目,我觉得无论我做什么我都做不好。我们应该创建一个程序,捕获3个项目,然后为每个项目捕获4位信息。AKA:项目: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()

如果有人能把我引向正确的方向,我将不胜感激。

您可以使用dict保存所有输入。它是允许使用的。您可以使用dict保存所有输入。它是允许使用的。