提问者:小点点

完成下面的算法,计算并打印三个月期间每个产品的总销售额,格式如下:


这让我困了很久,有人能帮帮我吗? 用粗体突出显示的东西是我需要帮助的东西,请尽量坚持使用格式!

            Total for product 1: xx
            Total for product 2: xx
            etc [3]

sales = [
         [0,0,0,0,0],
         [0,0,0,0,0],
         [0,0,0,0,0]
        ]
totalsales = [0,0,0,0,0]

for product  = 0 to 4
    print("Sales for product", product + 1)
    for month = 0 TO 2
        sales[month][product]  =  input("Enter quantity for month ", month + 1,":") 
**insert code here**


    next month
next product
**insert code here**

共1个答案

匿名用户

范围将从数字(从0到N)中获取一个序列,因此:

for product in range(5):
    print("Sales for product", product + 1)
    for month in range(3):
        sales[month][product]  =  input("Enter quantity for month ", month + 1,":") 

将迭代0,1,2,3,4的乘积值。