Home > Software engineering >  my code says dic not defined after I enter the correct credentials and select option 1
my code says dic not defined after I enter the correct credentials and select option 1

Time:02-10

  elif x==2:
  dic = {}
  def func():
    global dic

    while True:
        name = input(" PLEASE ENTER YOUR NAME CUSTOMER :- ")
        phone = int(input(" PLEASE ENTER YOUR CONTACT DETAILS :- "))
        order = float(input(" PLEASE ENTER NAME OF ORDER :- "))
        detail = input(" PLEASE ENTER THE DETAILS OF THE ORDER :- ")
        dic[name] = [phone, order, detail]
        a = input(" Do you want to enter more records enter (Yes/ No) :- ")
        if a == "No" or a == "no":
            break
        elif x == 3:
        def func ():
        suggestion = {}
        global suggestion
        while True:
        cname = input(" DEAR CUSTOMER PLEASE ENTER YOUR NAME ")
        sugg = input(" PLEASE ENTER YOUR VALUABLE SUGGESTION ")
        suggestion[cname] = [sugg]
        moresugg = input(" DO YOU WANT TO GIVE MORE SUGGESTIONS (YES/NO) :- ")
        if moresugg == "No" or moresugg == "no":
            break

        else:
            print(" WELCOME TO BAKERY STOCK MANAGEMENT ")
            print(" ENTER CORRECT CORRECT CREDENTIALS TO CONTINUE ")
            for _ in range(3):
               user = input("Enter username: ")
               pswd = input("Enter password: ")

            if user == "bakery_admin" and pswd == "bake42069":
            print(yellow("\t\t\t\tAccess Granted!\t\t\t\t", 'bold'))
            print(blue(" TO VIEW ADVANCE ORDERS PLACED INPUT 1\n", 'bold'))
            print(blue(" TO ADD THINGS TO SHOPPING LIST PRESS 2\n ", 'bold'))
            print(blue(" TO SHOW SUGGESTIONS STORE HAS GOT TODAY INPUT 3\n", 'bold'))
            z=int(input(magenta(" PLEASE ENTER A VALID OPTION: ", 'bold')))
            if z==1:
                for i in dic:
                    print(" Name : ", i)
                    print("Phone : ", dic[i][0], "\t", "Cost : ", dic[i][1], "\t", "Item : ", dic[i][2])
            break
        else:
            print("\t\t\t\tAccess Denied!\t\t\t\t")
        print("\t\t\t\tTry Again Later!\t\t\t\t")
    else:
        print("\t\t\t\tNo more attempts!\t\t\t\t")

##I cleaned up your paste of code.. Half of it was embeded, and half was not. In future posts make sure to neatly post your code and explanation of question to avoid being downvoted. We really only needed a small portion to answer your question.

CodePudding user response:

The variable dic is out of scope. Try moving it up:

dic = {}
if x==2:  
  def func():
    global dic

  •  Tags:  
  • Related