What is a Boolean?
A variable that can be either True or False
What does an if statement do?
Allows a program to behave differently based on circumstances
What type does the condition evaluate to in the following code?
barHeight = 1.9
elenaJump = 2.0
if elenaJump > barHeight:
print(“Elena cleared the bar!”)
Boolean
What are the three logical operators?
and, or, not
Will val be True or False?
val = 0.0037 / 100 == 0.000037
False
Will this code create a Boolean variable?
broughtSnack = true
NO - the first letter of the value must be capitalized:
e.g. True
e.g. False
In the following code, what type must condition evaluate to?
if condition :
…. Do something
A BOOLEAN
What does the following comparison operator mean?
!=
NOT equal to
What will print?
x = True
y = False
if not y:
print(“It’s Monday”)
It's Monday
Why should you use round() when you compare two numbers of type float?
Sometimes float numbers can be rounded in unexpected ways based on how Python computes them. Therefore, it is best to use round() in order to make sure both numbers are rounded the same way
Will this code cause an error? If yes, why?
broughtSnack = True
print(“Brought snack?” + broughtSnack)
YES - we cannot concatenate a String and a Boolean
What will print?
raining = True
if raining:
print("Make sure to bring an umbrella!")
else:
print("You do not need an umbrella today.")
Make sure to bring an umbrella!
What will print if the user types in "Kevin" into the user input?
name = input("What is your name? ")
if name == "Marsha":
print("Please be seated")
Sorry! You do not have a reservation
x and y
Both x and y must be True
(MULTIPLE CHOICE) Which of the following will correctly round the number stored in the variable pi to 3.14
a) round(pi)
b) round(pi, 3)
c) round(3, pi)
d) round(pi, 2)
Answer D
Fix this code:
broughtSnack = True
print(“Brought snack?” + broughtSnack)
print(“Brought snack?” + str(broughtSnack))
Find the errors (there are two):
if hasDog
print("Go walk")
else:
print("You don't need a walk")
On line 1, missing a colon
Line 2 is missing an indent
What is the variable type and value of someVal?
num = 10
someVal = num < 5
Boolean, False
What will print?
num = 6
if num < 0 or num >= 5:
print(“You get a key!”)
elif num == 4:
print(“You do not get a key.”)
else:
print(“Invalid role”)
You get a key
What are the two parameters in the parentheses of the round() function?
The first one is the number to be rounded, and the second is the amount of decimal places to round to.
What will print?
favoriteColor = "blue"
if favoriteColor == "blue":
if favoriteColor != "yellow":
print("must be blue")
elif favoriteColor == "blue":
if favoriteColor != "yellow":
print("I like purple")
else:
if favoriteColor == "blue":
print("blue is the best")
Must be blue
What do the comparison operators > and < do in the context of comparing two strings?
Later in the dictionary and earlier in the dictionary
If the user types in "student", what will print?
role = input(“What is your role at the school? ”)
if role == “teacher” and role != “student”:
print(“You get a key!”)
elif role == “student”:
print(“You do not get a key.”)
else:
print(“Invalid role”)
You do not get a key
How many decimal places does the round() function default to?
zero