Hello people!
Would be grateful for help.
Trying to solve sum_light task, but encountered with exception: TypeError: 'str' object cannot be interpreted as an integer
Code passes assertions from the task but fails after Check Solution.
Could you tell me where I've mistaken or should I take another direction in solution:
from datetime import datetime
from typing import List
import operator
def sumlight(els: List[datetime]) -> int:
bulbswitchedon = els[1::2]
bulbswitchedoff = els[::2]
timedelta = [bulbeon - bulbeoff for bulbeon, bulbeoff in zip(bulbswitchedon, bulbswitchedoff)]
seconds = timedelta[0].totalseconds()
#variable for incrementing datetime.timedelta items to recieve sum
b = time_delta[0] - time_delta[0]
if len(time_delta) > 1 and len(time_delta) < 3:
first_range = time_delta[1::2]
second_range = time_delta[::2]
p = [abs(first + second) for first, second in zip(first_range, second_range)]
another_seconds = p[0].total_seconds()
return another_seconds
elif len(time_delta) >= 3:
for a in time_delta:
b += a
seconds = b.total_seconds()
return seconds
return seconds
Thank you!
Created at: 2021/11/14 19:44; Updated at: 2021/11/15 06:19
The question is resolved.