迭代python3

时间:2018-03-11 17:15:06

标签: python

我是一名Python3新手..我想弄清楚为什么这不起作用。

我的代码:

#!/usr/bin/env python3


days = ['mon', 'tue', 'wed', 'thur', 'fri', 'sat', 'sun']

hours = []
count = 0

while count < 6:
    print('Please tell me how many hours you slept on:')
    for day in days:
        print(day)
        value = float(input())
        hours.append(value)
        v = sum(value)
        count = count + 1

avg =  ((v) / 7)

print("you slept an average of", round(avg), 'hours')

当我运行这个时,我得到以下错误:“TypeError'flove'对象不可迭代”回溯引用第18行'v = sum(value)'

谢谢

1 个答案:

答案 0 :(得分:0)

您需要更改

v = sum(value)

v = sum(hours)    #sum the list of sleep hrs