Download presentation
Presentation is loading. Please wait.
1
Nate Brunelle Today: Conditional Decision Statements
CS1110 Nate Brunelle Today: Conditional Decision Statements
2
Questions?
3
Last Time If, elif, else
4
Conditional decision Statement
if boolean expression: action elif boolean expression: another action else: yet another action 0 or more 0 or 1
5
Values and Types (not exhaustive)
Operators -50 ,0 ,5, 30, 512 int 3+7, 3*7, 3-7, 3/7 0.5, 1.2, float +, *, -, /, //, %, **, compare ‘hi’, “hi”, ‘hello world! ✃’ str +, * int Print, input function print() True, False bool and, or, not
6
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
7
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
8
Leap year rules Year is divisible by 4 Unless divisible by 100
div400 or (div4 and not div100)
9
“Truthiness” of all things in python
“Truish” Things “Falsish” things True False “True” 1, -1 0.0 None “ “ Empty things “False” ‘’ “” Advice: make sure every and, or has a bool on both sides
10
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
11
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.