-1
pins = {"Mike":1234, "Joe":1111, "Jack":2222}

pin = int(input("Enter your pin: "))

if pin in pins.values():


    nameinp = pins.get(pin)
    print("Hello Mr." + nameinp)



    fruit = input("Enter fruit: ")
    print(find_in_file(fruit))
else:
    print("Incorrect pin!")
    print("This info can be accessed only by: ")
    for key in pins.keys():
        print(key)


input()

So the idea is to make greeting screen for the particular person who inserted his own pin code, tried to research didn't find the answer, hope you will help!

Answers to all of you

There is no error, there is a question: how to make that when you put in password that is equal some value, and later when the system recognizes your password prints("Greetings" + value)

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 2
    What is your error? – Lithilion Nov 30 '18 at 08:27
  • You got your dictionary the wrong way round. You use a `key` to fastly get to data ... not look at all data to get the key (which is slooooooow). use `pins = {1234: "Mike", 1111:"Joe", 2222:"Jack"}` - to avoid `int()` throwing errors you might want to change to string-keys _or_ use techniques from [Ask User Input Until Valid](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) ` – Patrick Artner Nov 30 '18 at 08:40
  • why do you call `input()` below? did you name your function `input()` and therefore shadowing the normal `input()` that reads from stdin? – Patrick Artner Nov 30 '18 at 08:42
  • @PatrickArtner I guess to keep the window from closing before you get a chance to see the output of the script. – Rob Nov 30 '18 at 08:58
  • @Rob yep that is what i want by using that input() – Janis Anerauds Nov 30 '18 at 09:53

1 Answers1

2

You have the order of the dictionary key-value pairs interchanged. So instead of

pins = {"Mike":1234, "Joe":1111, "Jack":2222}

you should do

user_from_pin = {1234:"Mike", 1111:"Joe", 2222:"Jack"}

I took the liberty to change the variable name to be more descriptive what it actually does: Given a pin it returns the username. For example: user_from_pin[1111] == "Joe". The rest of the script should be adapted a little bit to work with this definition:

user_from_pin = {1234:"Mike", 1111:"Joe", 2222:"Jack"}
pin = int(input("Enter your pin: "))
user = user_from_pin.get(pin)
if user:
    print("Hello Mr." + user)
    fruit = input("Enter fruit: ")
    print(find_in_file(fruit))
else:
    print("Incorrect pin!")
    print("This info can be accessed only by: ")
    for value in pins.values():
        print(values)
input()
Rob
  • 3,418
  • 1
  • 19
  • 27