# File: if2.py # Program to demonstrate various forms of the "if" statement # # Matt Bishop, ECS 36A, Winter 2019 # # # This shows the "if" statement in various forms # # n = int(input("Enter a 0 or a 1 or a 2 or a 3: ")) # # first, the "if" # if n == 0: print("You typed a 0!") # # now, the "if-else" # if n == 0: print("You typed a 0!") else: print("You didn't type a 0") # # now, the "if-elif-else" # if n == 0: print("You typed a 0!") elif n == 1: print("You typed a 1!") elif n == 2: print("You typed a 2!") else: print("You didn't type a 0 or a 1 or a 2") # # now, the "nested if" # if n > 1: print("You typed something greater than 1!") if n < 3: print("You typed something greater than 1 and less than 3 -- or, 2") else: print("You typed something greater than 1 and not less than 3 -- or 3") else: print("You typed something not greater than 1!") if n < 1: print("You typed something not greater than 1 and less than 1 -- or, 0") else: print("You typed something not greater than 1 and not less than 1 -- or 1") pwd = input("Now type your password: ") if pwd == 'abcde': print("Log in successful . . . if this were a real login") elif pwd == 'fghij': print("Log in may have worked") else: print("Log in failed!")