mercredi 6 mai 2020

Reassigning variable from None to Value python

I am trying make a script that will accept 3 inputs first is username as input second and third are bar codes i need to compare, but after the first input of the user I want it to stop asking me for the user and just save and use it and cant seem to do it. I am assigning the user_global to be None at start so can I use an if to run the get_user function but when the script runs it second loop time it gives None as value to the user again and i cant seem to remember how to remove the user from the loop and save it after the first iteration because i am real dumb, as I stated before. Here is the code:

while True:

def get_user():
    user=input("Enter User :")
    user_global = user
    print(user)
    print(user_global)

user_global = None


if user_global == None:
    get_user()


a = datetime.datetime.now()
print(a)

def gun_read():
    barcode1=input("Please the first barcode the barcode!?")
    print(barcode1)
    barcode2=input("Plese read the secdon barcode?!")
    print(barcode2)
    if barcode1 == barcode2:
        print("GREEN LIGHT!!")
    else:
        print("you fcked up broooo!!")


# if os.cwd() ima csv file add to csv else create csv

gun_read()

Help, please ? Also ignore prints and datetime.

Aucun commentaire:

Enregistrer un commentaire