Booleans
If Statements
Comparison Operators
Logical Operators
Float Rounding
100

What is a Boolean?

A variable that can be either True or False

100

What does an if statement do?

Allows a program to behave differently based on circumstances

100

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

100

What are the three logical operators?

and, or, not

100

Will val be True or False?

val = 0.0037 / 100 == 0.000037

False

200

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

200

In the following code, what type must condition evaluate to?

if condition :

  …. Do something

A BOOLEAN

200

What does the following comparison operator mean?

!=

NOT equal to

200

What will print?

x = True

y = False

if not y:

  print(“It’s Monday”)

It's Monday

200

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

300

Will this code cause an error? If yes, why?

broughtSnack = True

print(“Brought snack?” + broughtSnack)

YES - we cannot concatenate a String and a Boolean

300

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!

300

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

300
In the following expression, which values must the variables x and y have in order for the whole expression to evaluate to True?


x and y

Both x and y must be True

300

(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

400

Fix this code:

broughtSnack = True

print(“Brought snack?” + broughtSnack)

print(“Brought snack?” + str(broughtSnack))

400

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

400

What is the variable type and value of someVal?

num = 10

someVal = num < 5

Boolean, False

400

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

400

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.

500

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

500

What do the comparison operators and do in the context of comparing two strings?

Later in the dictionary and earlier in the dictionary

500

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

500

How many decimal places does the round() function default to?

zero

M
e
n
u