coding ex problem5

PHOTO EMBED

Fri Jan 20 2023 02:40:53 GMT+0000 (Coordinated Universal Time)

Saved by @Shaghaf_2000 #python

# 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")
content_copyCOPY