Class 19 — Wednesday March 2

Introduction to "if" and "else"

"Fall in love with the process and the results will follow" -Eric Thomas


Look both ways


Agenda


Downloads


Yesterclass


To do


Program logical_operators.py

Program run

##### Logical values (bool)

True

False

<class 'bool'>

<class 'bool'>

##### 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)]

Problem begins_with_a_vowel.py

Enter text: apple

Text begins with vowel

Enter text: banana

Text does not begin with vowel

Enter text: Orange

Text begins with vowel



Problem daisy_daisy.py

Enter day of week: Sunday

Weekend day

Enter day of week: monday

Start of school week

Enter day of week: TUESDAY

School day

Enter day of week: Wednesday

School day

Enter day of week: Thursday

School day

Enter day of week: Friday

End of school week

Enter day of week: Saturday

Weekend day


 


  🦆 © 2022 Jim Cohoon   Resources from previous semesters are available.