samedi 21 décembre 2019

Variable Printing Too Much

I am creating an NFC door lock and with my current code when my NFC card is scanned it Unlock's then Locks the door instantly. I am trying to make it so it will unlock and then wait for me to scan again so then it will lock again. This is just a simplified version although it prints the same problem. The variable is what allows the card to print and if it matches what I have written it will Unlock the door, although it also locks the door right after. What do I need to do to fix this?

def main():

    var ="Card Read: 1234"
    if var=="Card Read: 1234":
        print("Door Unlocked")

    else:
        print("Invalid")
        main()

    var ="Card Read: 1234"
    if var=="Card Read: 1234":
        print("Door Locked")
        main()

    else:
        print("Invalid")

main()

Aucun commentaire:

Enregistrer un commentaire