I’m beginning to learn python and I’ve created this simple program which asks the user for the pin-code. I’ve indicated an amount of attempts and wrote a function which exits the program in case this amount is exceeded. The code has been working perfectly, but today when I tried to run it, it exits the program right away (Output: “Process finished with exit code 0”). Could anyone please tell me what’s wrong with it? Thanks in advance.
Code:
import time
def pin_access():
try:
def failed_access():
print(‘Too many wrong attempts. Shutting down.’)
time.sleep(1)
print(‘—————–‘)
time.sleep(1)
exit(0)
count = 0
while count < 4:
enter = int(input('Please use your pin code to start: '))
count += 1
if enter != 1234:
print(f'Wrong pincode, attempts left: {4 - count}.')
if count == 4:
failed_access()
if enter == 9207:
break
if enter == 1234:
print('Pin code accepted.nInitializing...')
time.sleep(1)
print('...')
time.sleep(1)
print('...')
print('Welcome to the Program!n')
time.sleep(1)
except ValueError:
print('Please use only numbers for your pin-code!')
time.sleep(1.5)
pin_access()
except KeyboardInterrupt:
print("n*Program has been terminated by user*")
time.sleep(2)
exit(0)
if name == ‘main‘:
pin_access()
PyCharm giving me only one warning: “Local variable ‘enter’ might be referenced before assignment” which I believe is not realated to this issue.
Leonard Betts is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.