Skip to content

Campbell-law/sept-19-flow-control

Repository files navigation

Sept 19 Flow Control

Fork this Repo clone it to your drive and do the exercises at: sept-19.py

If Then Else Flowcharts

XKCD

A basic If statement

if

n = 10
if (n > 15): 
   print ("10 is less than 15") 
print ("I am Not in if") 

If with an Else

if_else

n = 20; 
if (n < 15): 
    print ("n is smaller than 15") 
    print ("n is in if Block") 
else: 
    print ("n is greater than 15") 
    print ("n in else Block") 
print ("n not in if and not in else Block") 

If Else Elif

ladder

n = 20
if (n == 10): 
    print ("i is 10") 
elif (n == 15): 
    print ("i is 15") 
elif (n == 20): 
    print ("n is 20") 
else: 
    print ("n is not present") 

Nested Ifs

nested

n = 10
if (n == 10): 
    #  First if statement 
    if (n < 15): 
        print ("n is smaller than 15") 
    # Nested - if statement 
    # Will only be executed if statement above 
    # it is true 
    if (n < 12): 
        print ("n is smaller than 12 too") 
    else: 
        print ("n is greater than 15")  

About

September 12 class -- Chapter 2 Flow Control

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages