我是一名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)'
谢谢
答案 0 :(得分:0)
您需要更改
v = sum(value)
到
v = sum(hours) #sum the list of sleep hrs