Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionaries help
#1
My code gives me back all the names in the dictionary when I want it to only give back the name that corresponds with the pin. Any reason why and how I could fix it is appreciated. Thanks!

Here's my code:


import time
count=0
correct_pin = {"Peter":352, "james":123, "richard":321}

while count<4:
    pin = int(input("What is your password: "))

    if pin in correct_pin.values():
       print ("Correct! You are now logged in, ")
       for key in correct_pin.keys():
           print (key)
       time.sleep(1)
       print()
       print()
       print("Opening Codes")
       time.sleep(1)
       print("Please Wait...")
       print()
       time.sleep(3)
       g = open("Codes.txt","r")
       s = g.read()
       print(s)
       g.close()
       exit()
       break


    elif pin not in correct_pin.values() and count<=4:
        print('Wrong! Try again')
        count= count+1

if count<=4:
   print("You got it wrong too many times. Account locked!")
Reply


Messages In This Thread
Dictionaries help - by Rayaan - Aug-01-2019, 01:37 PM
RE: Dictionaries help - by ichabod801 - Aug-01-2019, 01:46 PM
RE: Dictionaries help - by perfringo - Aug-01-2019, 02:07 PM
RE: Dictionaries help - by Friend - Aug-01-2019, 02:49 PM
RE: Dictionaries help - by perfringo - Aug-01-2019, 08:29 PM
RE: Dictionaries help - by Malt - Aug-02-2019, 06:21 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020