# problem5:
# store a number as a password:
# list must be outside the loop:
import time
guesses = []
password= '0000'
while True:
# to exit the program
try:
# Take user input:
gussed = input("Gusse a password that consists from 4 numbers: ")
# convert to string:
gussed = str(gussed)
# conditions:
if gussed == password:
print("Password correct!")
# leave the loop
break
else:
print("Password incorrect")
guesses.append(gussed)
if len(guesses)>3:
print("You are banned because spamming, please try again after 3s. ")
guesses = []
time.sleep(3)
else:
guesses.append(gussed)
print(guesses)
#guesses.append(gussed)
except KeyboardInterrupt:
print("exist")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter