HI i am new tp pi and python and wanted to create something that simply turns on and off a led.

It does not seem to work and not sure why?

here is the python script:

    from gpiozero import LED, Button

from time import sleep

led = LED(2)

while True:
    range(100) and None

Here is a pic of my pi 3 wiring:

enter image description here

I followed this guide


  • 4
    Have you tried turning your LED around, they will only work in one direction.
    – CoderMike
    Jun 18, 2020 at 10:59
  • Awsome turning around the led fixed it!
    – Jonathan
    Jun 18, 2020 at 11:08
  • @CoderMike Are you going to make that an answer to get credit for it? Otherwise someone else might run with the glory.
    – Mast
    Jun 18, 2020 at 16:53
  • How do I mark a comment as the answer?
    – Jonathan
    Jun 18, 2020 at 16:59
  • You can't mark a comment as an answer.
    – Seamus
    Jun 19, 2020 at 1:08

1 Answer 1


The problem is caused by the line range(100) and None which is causing your loop to exit. You need to remove it. Where did it come from? It's not in the docs.

If you want to loop 100 times, change the while True: to for i in range(100):

Also it's probably just the way you pasted in the code here but your first line is indented, just make sure it isn't indented in your program.

  • HI. tried that and it did not work, the led light does not turn on. i added a print(i) to check if its hitting atht bit of the code and it does
    – Jonathan
    Jun 18, 2020 at 8:39
  • 1
    "The problem is caused by the line range(100) and None" No, it isn't. That expression is well-formed so it's not throwing an exception to terminate the loop. It's not part of the while condition so its result does not control the while. It's also so trivial that its execution time should not be significantly affecting the rest of the loop operations. It is indeed pointless here, but it is certainly not the cause of the failure.
    – nobody
    Jun 18, 2020 at 16:51
  • Oh yes, my mistake. Jun 18, 2020 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.