im creating a code that asks the user to input their password as digits from a randomly generated string of digits between 1 and 3 that is beneath.
for example,
pin: 0 1 2 3 4 5 6 7 8 9
ran: 1 2 2 3 1 2 1 3 2 1
if the user's password is 56789, they would need to enter 21321
import random
# Store the actual PIN as a list of integers
pin = [5, 6, 7, 8, 9]
# Generate random numbers for digits 0 to 9
randNumbers = [random.randint(1, 3) for x in range(10)]
# Create lists to map random numbers to digits
random_to_digit = [None, '0', '1', '2']
# Output digits 0-9 in a single line
print("PIN:", end=' ')
for i in range(10):
print(i, end=' ')
# Output the corresponding random digits below in a single line
print("\nNUM:", end=' ')
for i in range(10):
print(random_to_digit[randNumbers[i]], end=' ')
# Request and get the input response from the user
pwdEntry = input("\nPlease enter your converted password: ")
if pwdEntry[0] == randNumbers[5] and pwdEntry[1] == randNumbers[6] and pwdEntry[2] == randNumbers[7] and pwdEntry[3] == randNumbers[8] and pwdEntry[4] == randNumbers[9]:
print("success")
else:
print("failure")
i tried comparing each item the user entered to the position in the list that the correct digit they would need to enter since the password 56789 is constant but it always results in failure.
Aucun commentaire:
Enregistrer un commentaire