Aug-21-2022, 03:12 PM
Hi! Total programming noob (not just in Python) here trying to make his code a bit shorter and more readable.
I'm trying to put functional LEDs in an array or list to make it easier to turn two or more on at the same time. However it ends in:
Am i overthinking it or missing something obvious?
I'm trying to put functional LEDs in an array or list to make it easier to turn two or more on at the same time. However it ends in:
Error:AttributeError: 'list' object has no attribute 'on'
The code for it is:import time from gpiozero import Buzzer from gpiozero import LED red = LED(2) yellow = LED(3) green = LED(4) blue = LED(14) buzzer = Buzzer(15) leds = [red, yellow, green, blue] password = int(input('xxxxxxxx: ')) if password != xxxx: print('xxxxxxxx') for i in range(3): red.on() buzzer.on() time.sleep(0.2) red.off() buzzer.off() time.sleep(0.2) elif password == xxxx: print('xxxxxx') for i in range(3): leds.on() buzzer.on() time.sleep(0.2) leds.off() buzzer.off() time.sleep(0.2) green.on()The error is in line 25 and 28. I tried searching for a solution or how to implement it correctly, however any array or list functon i find uses it for text data.
Am i overthinking it or missing something obvious?