这是我的整个代码:

days=["Sunday: ", "Monday: ", "Tuesday: ", "Wednesday: ", "Thursday: ", "Friday: ", "Saturday: "]
demand=[]
temp=[]
demand=[15, 20, 25, 18, 20, 22, 14]
while demand[0]>0 or demand[1]>0 or demand[2]>0 or demand[3]>0 or demand[4]>0 or demand[5]>0 or demand[6]>0:
    min1=min(demand)
    ind1=demand.index(min1)
    temp=demand.copy()
    temp[ind1]=100000
    min2=min(temp)
    ind2=temp.index(min2)
    print(min1, ind1, min2, ind2)
    for i in range(7):
        if i != ind1 and i != ind2:
            demand[i]-=1
    print(demand)
print(days[0], demand[0]+15, days[1], demand[1]+20, days[2], demand[2]+25, days[3], demand[3]+18, days[4], demand[4]+20, days[5], demand[5]+22, days[6], demand[6]-14)


我想垂直打印最后一个print命令,这样最终结果如下:

Sunday:     15
Monday:     20
Tuesday:    25
Wednesday:  18
Thursday:   20
Friday:     22
Saturday:   14

最佳答案

一种简单的方法是对print循环中的每一行使用单独的for语句:

offsets = [15, 20, 25, 18, 20, 22, -14]
for day in range(7):
    print(days[day], demand[day] + offsets[day])

10-08 05:16