# examples of conditional expressions # # Matt Bishop, MHI 289I, Fall 2024 # # first, an "if" value = 0 if value > 0: sgn = 1 else: sgn = 0 print("in regular if, sgn should be 0 --", sgn) # now as a conditional expression sgn = 1 if value > 0 else 0 print("in conditional expression, sgn should be 0 --", sgn) # now an if .. else if .. else value = -200 if value > 0: sgn = 1 elif value == 0: sgn = 0 else: sgn = -1 print("in regular if/elif/else, sgn should be -1 --", sgn) # now as a conditional expression sgn = 1 if value > 0 else 0 if value == 0 else -1 print("in conditional expression, sgn should be -1 --", sgn)