Class 18 — Monday October 4

Logical values and decision

May the light of peace — For you and your families — Always shine brightly


Look both ways


Agenda


Transitioning


Downloads


To do


Program can_you_relate.py

Three program runs

Enter number: 12

Enter number: 11

12 < 11 : False

12 > 11 : True

12 <= 11 : False

12 >= 11 : True

12 == 11 : False

12 != 11 : True

Enter number: 3

Enter number: 14

3 < 14 : True

3 > 14 : False

3 <= 14 : True

3 >= 14 : False

3 == 14 : False

3 != 14 : True

Enter number: 7

Enter number: 7

7 < 7 : False

7 > 7 : False

7 <= 7 : True

7 >= 7 : True

7 == 7 : True

7 != 7 : False



Program logical_operators.py

Program run

##### Logical values (bool)

True

False

##### Logical and

True and True = True

True and False = False

False and True = False

False and False = False

##### Logical or

True or True = True

True or False = True

False or True = True

False or False = False

##### Logical negation

not True = False

not False = True

##### Logical includes

1 in [3, 1, 4, 1, 5] = True

2 in [3, 1, 4, 1, 5] = False

##### Logical exclusion

1 not in [3, 1, 4, 1, 5] = False

2 not in [3, 1, 4, 1, 5] = True



The why, what, and how of the basic if statement

if ( logical expression ) :

    action1

else :

    action2

if ( logical expression ) :

    action


Program acid_test.py

Three program runs

Enter pH level: 6.5

True

Enter pH level: 7.0

False

Enter pH level: 7.5

False



Program what_color_will_my_chrysanthemums_be.py

Enter soil pH level: 6.5

pink

Enter soil pH level: 7

blue

Enter soil pH level: 7.5

blue


Chrysanthemum morifolium 08NOV; 池田正樹 (talk)masaki ikeda [Public domain]


Chrysanthemum Blue by Sugeesh at Malayalam Wikipedia [CC BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0)]