1  
2
3
4
5
while True:                           # endless loop
    pin = input("Enter PIN: ")
    if pin == "1234":                 # PIN ok -> discontinue loop
        break                         
print("PIN ok")


UML 1.x activity diagram of a PIN verification


For advanced programmers:

 1  
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def login(code):                       # definition of function
    for i in range(3):                 # counting loop (i=0; i<=2; i=i+1)
        pin = input("Enter PIN: ")
        if pin == code:                # PIN okay
            return 0
    else:
        return 1                       # PIN wrong

if login("1234") == 0:                 # call of function and check of return value
    print("PIN ok")
else:
    print("Card has been retracted.")


UML 1.x activity diagram of a PIN verification (advanced solution)

Last modified: Monday, 13 March 2023, 8:07 AM