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:


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, 4 November 2019, 10:59 PM