Nate Brunelle Today: Conditional Decision Statements CS1110 Nate Brunelle Today: Conditional Decision Statements
Questions?
Last Time If, elif, else
Conditional decision Statement if boolean expression: action elif boolean expression: another action else: yet another action 0 or more 0 or 1
Values and Types (not exhaustive) Operators -50 ,0 ,5, 30, 512 int 3+7, 3*7, 3-7, 3/7 0.5, 1.2, 0.333333 float +, *, -, /, //, %, **, compare ‘hi’, “hi”, ‘hello world! ✃’ str +, * int Print, input function print() True, False bool and, or, not
and, or, not examples x<2 and x>0 x<0 or x>2 not x>2 When all things are true X=1 x<0 or x>2 When any of the things are true X=-1 X=15 X=2 X=0 not x>2 When the thing is false
and, or, not and or not True if all things are True False if any things are False or True if any things are True False if all things are False not True if the thing was False False if the thing was True
Leap year rules Year is divisible by 4 Unless divisible by 100 div400 or (div4 and not div100)
“Truthiness” of all things in python “Truish” Things “Falsish” things True False “True” 1, -1 0.0 0.0000001 None “ “ Empty things “False” ‘’ “” Advice: make sure every and, or has a bool on both sides
What do and, or evaluate to? Evaluate to the first truish thing If all things are falsish, give the last falsish thing And Give the first falsish thing If all things are truish, give the last truish thing
Chained Comparitors 1 < 2 < 3 1 < 2 and 2 < 3 True 1 < 2 < 3 1 < 2 and 2 < 3 1 < 2 > 0 < 8 > -5 == -5 Gives true True