Creating Random Pin & More Debugging

Create Pin or Randomize pin based on user input and verifying in login

Kenny Hin
3 min readJul 9, 2022

TO DO: PIN options

Prompting user to create username and PIN (Registration)

Give option to create own pin or have ATM create random pin based on how many numbers you want.

ATM create random pin

For the first half: Under the hood

Randomizing pin lines start at Line 34 — Line 49.

Line 39

Assigning pin_length to the user’s input on line 40.

Setting this number as the “end” length + 1 in the for loop. The +1 is because length would not reach selected number, only in between. Ex: if user chose 4, random choice would only add 3 numbers to the list because it would only loop through block 3 times, when it hits 4, it breaks.

Line 42–43

random.choice will randomly grab from the list of numbers on line 34 and add it to the empty list assigned by random_pin_list. Line 43 will shuffle those numbers before restarting the loop.

After Line 41’s loop is done executing, random_pin_list will look something like this: [‘3’, ‘0’, ‘9’, ’1']

Now we need to extract each individual integer and assign it to line 36 empty string.

Line 45–46

So we will now loop through random_pin_list, taking each individual number and add it to the random_pin. REMEMBER: to grab single items from list, the “num” are those individual numbers. Thats why in line 46, random_pin adds “num” at each iteration of loop.

2nd Half: Under the hood

Create your own Pin if Else block is executed

Line 50–52

If user chooses anything but Y, they will be prompted to create their own PIN.

LOGIN + verification

Under the Hood:

Ran into an issue with validating both pins. Lines 64 and Line 67 validates both pins. The solution lies in line 62.

Line 62

The problem was making sure all data types being compared need to be the same data type. REMEMBER user input returns STRINGS.

In this code block, everything i’m comparing are strings. random_pin is a string because it was added from a list mentioned above.

I wrapped “pin” in an int above:

and so when i was comparing login_pin with pin, i was comparing and integer and a string so it kept giving me an ValueError.

Instead of wrapping pin in str on line 62, i could have just took off the int wrap above.

--

--