π Conditionals
November 30, 2016Learning Targets
- I can write conditionals in Python using
if
andelse
. - I can predict the output of conditionals in Python.
Do Now (in Classroom)
What data type is required for a conditional?
Hint: The answer does not depend on the programming languageβ it will be the same type of data in Python, SNAP, JavaScript, etcβ¦
Conditionals
if #something true
# run this indented code
else:
#run this indented code
Quick check
# What's the difference between
school = "F&T"
#and
223 == 223
# what about...
223 = "F&T"
Python Comparison Operators
Operator | Description | Example |
---|---|---|
== | equal to | x == 2 |
! | not equal to | y != 3 |
> | greater than | 4 > 3 |
< | less than | 1 < 1 |
>= | greater than or equal to | x >= 2 |
<= | less than or equal to | y <= 3 |
"""
What will print after each conditional is run?
"""
# Number 1:
if 5<2:
print("I am right")
else:
print("I am wrong")
# Number 2:
if 5>2:
print("I am right")
else:
print("I am wrong")
if
evenβ¦
How can we tell if a number is even or odd?
%
This is not the percentage sign. I mean, it is, but in Python, it means modulo or mod. What?
It divides one number by another and returns the remainder. Like this:
print(4 % 3)
print(1040934 % 2)
print(1040934 % 2)
Before you start calculating, what are the only possibilities of each modulo operation?
Grouping
Finish "String Methods"
(or submit in repl):
- Alyssa
- Annalis
- Anthony
- Atiba
- Brianna
- Carlos
- Dallana
- David
- Devonte
- Emarie
- Jeremiah
- Jose
- Kathryn
- Matthew
- Michael