2 Sequence & Selection

1
2
3
4
5
age=12
if age  > 17:
    print("Can drive")
else:
    print("Too young to drive a car")

Multiple if.. Statements

 

1
2
3
4
5
6
7
8
9
10
11
12
score=72

if score  >  90:
    print("A")
elif score > 80:
    print("B")
elif score > 70:
    print("C")
elif score >50:
    print("D")
else:
    print("E")

Recap

The following program combines what we have learnt so far: getting input from the user, string manipulation and selection

1
2
3
4
5
6
7
8
9
print("enter a password that must be greater than 8 characters")
passwd=input("Type in the password")

passwdlen=len(passwd)

if passwdlen >= 8:
    print("Password accepted")
else:
    print("Password too short")