如何修复以下代码以求平均步数?

问题描述 投票:0回答:1

#365 天内平均步数 月 = ('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', “八月”、“九月”、“十月”、“十一月”、“十二月”) 天 = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) myfile = open('steps.txt', 'r')

for x in range(12):
    total = 0
    average = 0
    for y in range (days[x]):
        steps = int(myfile.readline())
        total += steps

    average = total/ days[x]
   
print(f"The average steps taken in the month of {month[x]} is {average}")
python syntax-error python-3.7
1个回答
0
投票
    for x in range(12):
        total = 0
        for y in range(days[x]):
            steps = int(myfile.readline())
            total += steps
        average = total / days[x]
        print(f"The average steps taken in the month of {month[x]} is {average:.2f}")
© www.soinside.com 2019 - 2024. All rights reserved.