2

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")
ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110
  • 1
    Can you quote and add the error to the question. – Error - Syntactical Remorse Sep 11 '17 at 14:52
  • Welcome to StackOverflow! `NameError` is a very common exception in `python`, and implies this is a very basic bug. It's likely saying that the `button_a` variable isn't defined yet -- python is good about creating variables as you need them, but it can't just make up a value for `button_a` without knowing what it is or what value it's supposed to be, so it raises an Exception to make it loud and clear to you that this is a bug. What makes you think that `button_a` is defined? – CivFan Sep 11 '17 at 16:42

2 Answers2

1

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.

Sean Houlihane
  • 1,698
  • 16
  • 22
0

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

Abdullah
  • 21
  • 7