I am a Python3 newbie.. I am trying to figure out why this does not work.
my code:
#!/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')
When I run this I get the following error: "TypeError 'float' object is not iterable" the traceback references line 18 'v = sum(value)'
thank you
You need to change
v = sum(value)
to
v = sum(hours) #sum the list of sleep hrs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.