''' Purpose: introduce decision making ''' # determine chrysanthemum color given an input soil pH level # acidic soil produces pink chrysanthemums # non-acidic soil produces blue chrysanthemums # acidity threshold ACIDIC_THRESHOLD = 7.0 # samples less than threshold are acidic # get soil pH level of interest reply = input( 'Enter soil pH level: ' ) pH = float( reply ) print( ) # analyze and report effect on chrysanthemums # if acidic print 'pink'; otherwise print 'blue' # if statements --> allow us to selectively execute certain blocks of code based on some conditions # if # ( logical expression ) -- parentheses not required but unless you have a specific order you want to evaluate # the expression (a and b) or c vs a and ( b or c ) # other languages will require () # we include () as a style rule so it makes it easier to see the expression # : # if the ( logical expression ) is True, then we do what's in the if statement # if it's False, then we do something else if ( pH < ACIDIC_THRESHOLD ): # if pH is less than 7.0, then we print the string 'pink' print( 'pink' ) # need to do some action underneath if: # cannot leave blank --> error else: # else is OPTIONAL --> if there's on else: and if the if condition is not met --> will just do nothing and not # do the action underneath the if statement # if you do have an else: # else statement does NOT need a condition, because it assumes that the condition of the # (logical statement) in if is not met # else will execute if the logical statement in the if statement does not work out (False) # if pH is NOT less than 7.0 (or greater than or equal to) # then do these lines of codes, SKIP line 35 (or anything indented underneath if print( 'blue' ) # then print the string 'blue' # if you have an else: you need some action, cannot leave blank # all done # you can have nested if/else statements within another if/else statements # can have a loop inside if/else statements # inside loop, can have more if/else statements # if ( something is True ): # for loop_var in sequence: # if loop_var == 1: # print( 'something' ) # else: # print( 'idk' ) # else: # print( '🦆' )