NameError on Line 8? (if button_a.is_pressed)

338 Views Asked by At

There is a name error, but I can't figure it out. It's on line 8, at where the buttonpress is. This is for an attendance marking program that I am doing.

Any help and improvements would be greatly appreciated.

start = 0
ind = 0
ind1 = 5
c = {'1': [], '2': [], '3': [], '4': [], '5': [], '6': [], '7': [], '8': [], '9': [], '10': [], '11': [], '12': [], '13': [], '14': [], '15': [], '16': [], '17': [], '18': [], '19': [], '20': []}
d  = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '10': 0, '11': 0, '12': 0, '13': 0, '14': 0, '15': 0, '16': 0, '17': 0, '18': 0, '19': 0, '20': 0}
#Registering#
if button_a.is_pressed:
    start=1
    display.scroll("Index No.")
elif button_b.is_pressed:
    start=0


    if start==1: 
        rgs=''
        ind=0
        while True:
            rgs=''
            while rgs=='':
               display.scroll("Password")
               for i in range(8):
                   if button_a.is_pressed:
                       rgs+='0'
                   elif button_b.is_pressed:
                       rgs+='1'
               for j in range(20):
                   if c[j][1]==rgs:
                       rgs=''
                       display.scroll("PASSWORD USED")
                   else:
                       for q in range(20):
                           if c[q]==ind:
                               c[q][1]=rgs
                           display.show("OK")
2

There are 2 best solutions below

1
On

Assuming the tag is correct, and you're trying to run this on a micro:bit, the magic which is missing at the start of your program is

from microbit import *

Without this, none of the platform specific elements are present - i.e. the buttons and the display.

0
On

Make if button_a.is_pressed to if button_a.is_pressed() because it is a function.