0
Code gives IndexError: index out of range. I don't know what's happening or how to solve it. Pls help
I am making a visual representation of how my math problem looks like and now I just don't understand why it's not working and am very close to completely giving up. I've been coding for the last 3 hours and haven't gotten it done. https://code.sololearn.com/c86zeR58axe6/#py When I need to test the value of an index in my module makeList, it says IndexError: list index out of range. Please help!
5 Respuestas
+ 1
If you need indexes, you can write
for i in range(len(lights)):
and then use i as an index.
+ 1
Line 9: for i in lights - it means that i is an element of list named lights, but you use it as an index. So you get index out of range.
0
How do I do it then? lightsV is dependent on lights. They correspond in a way. I made it based on this problem:
The holiday season was fast approaching and Miss Snow, who loved the season more than anyone, decorated the beautiful tree in her yard with a string of 300 lights. She turned the lights on and marveled at the sight. At midnight, however, she noticed something strange happened—bulbs started blinking on or off every second. In the 1st second, every bulb was on; in the 2nd second, every second bulb, starting with bulb #2, blinked off; in the 3rd second, every third bulb, starting from bulb #3, blinked off or on (some bulbs that were off blinked on again—for example, bulb #6 blinked on again); in the 4th second, every fourth bulb, starting with bulb #4 blinked off or on; and so on. This continued for a while, and then stopped.
0
Everyone can do it, good luck!)
0
Oh yeah! I forgot that thanks! YES!!! MY CODE WORKS NOW!!! Sorry for Caps