2021年4月10日星期六

Python 3 - How to create a code that allows the user to input both letters and numbers when entering their password

I'm very new to python and have been assigned homework where my professor wants us to create a loop for when a user enters their pin (has to be numbers) to log in. The code has to allow only 3 attempts and has to lock out the user for 10 seconds (if PW is wrong) before looping back to allowing them to attempt to login in again.

So far I have been successful in creating a basic code for allowing 3 attempts.

original_pin = 1122    count=0    while count < 3:        secret_pin = int(input('Enter Your Pin: '))        if secret_pin == original_pin:            print('DOOR UNLOCKED!!')          break        else:          print('WRONG PIN!! (TRY AGAIN!)')          count += 1  

The issue I'm currently having is that if the user enters a letter, I get this error message (I entered "d") I'm not sure what to change in line 7 so that letters can be accepted as a input.

Traceback (most recent call last):    File "C:/Users/Indias/AppData/Local/Programs/Python/Python39/test.py", line 7, in <module>      secret_pin = int(input('Enter Your Pin: '))  ValueError: invalid literal for int() with base 10: 'd'  
https://stackoverflow.com/questions/67040706/python-3-how-to-create-a-code-that-allows-the-user-to-input-both-letters-and-n April 11, 2021 at 09:31AM

没有评论:

发表评论