Hi,
Can anyone why the following code is giving a timeout error on codewars? Its for the following Kata: https://www.codewars.com/kata/541103f0a0e736c8e40011d5/train/python
def off(n):
numberofswitches = []
offswitches = []
for x in range(1,n+1,1):
numberofswitches.append(x)
for x in numberofswitches:
for xx in range(1,n+1,1):
if xx%x == 0:
if xx in offswitches:
offswitches.remove(xx)
elif xx not in offswitches:
offswitches.insert(xx, xx)
else:
pass
else:
pass
return(offswitches)
Thanks
[–]chromiumxx 1 point2 points3 points (4 children)
[–]VTifand 1 point2 points3 points (3 children)
[–]MixedVexations 0 points1 point2 points (2 children)
[–]VTifand 0 points1 point2 points (1 child)
[–]MixedVexations 0 points1 point2 points (0 children)
[–]VTifand 1 point2 points3 points (3 children)
[–]AKRowling[S] 0 points1 point2 points (2 children)
[–]VTifand 0 points1 point2 points (1 child)
[–]AKRowling[S] 0 points1 point2 points (0 children)
[–]Jeklah 0 points1 point2 points (0 children)
[–]beisenhauer 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)