Unit 4 Flashcards

1
Q

What does this program print?

favorite_color = “blue”

if favorite_color != “blue”:
if favorite_color != “red”:
print(“Must be yellow”)
elif favorite_color == “blue”:
if favorite_color != “yellow”:
print(“Must be blue”)
elif favorite_color == “blue”:
if favorite_color != “yellow”:
print(“I like purple”)
else:
if favorite_color == “blue”:
print(“Blue is the best”)

A

Must be blue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How would you round the number held in the variable pi to 3.14?

pi = 3.14159265

A

round(pi, 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why should you use round when you compare two numbers that have type float?

A

Sometimes 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What will print to the screen when the following program is run?

number = 5
greater_than_zero = number > 0
print(type(number))

A

<type ‘int’>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What will print to the screen when the following program is run?
number = 5
less_than_zero = number < 0
print(type(less_than_zero)

A

<type ‘bool’>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What will be the output of this program?
number = 5
greater_than_zero = number > 0

if greater_than_zero:
print(number)

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

number = 5
greater_than_zero = number > 0

if greater_than_zero:
if number > 5:
print(number)

A

Nothing will print

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

number = 5
less_than_zero = number < 0

if less_than_zero:
print(number)

number = number-10
less_than_zero = number < 0

if less_than_zero:
print(number)

A

-5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

number = 5
greater_than_zero = number > 0
less_than_zero = number < 0

if greater_than_zero:
print(number)
if less_than_zero:
print(number + 1)
if greater_than_zero and less_than_zero:
print(number + 2)
if greater_than_zero or less_than_zero:
print(number + 3)

A

5
8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

above_16 = True
has_permit = True
passed_test = False

if above_16 and has_permit and passed_test:
print(“Issue Driver’s License”)
elif above_16 or has_permit or passed_test:
print(“Almost eligible for Driver’s License”)
else:
print(“No requirements met.”)

A

Almost eligible for Driver’s License

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

number_one = 5
number_two = 10

if number_one == 5:
print(1)
if number_one > 5:
print(2)
if number_two < 5:
print(3)
if number_one < number_two:
print(4)
if number_one != number_two:
print(5)

A

1
4
5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

number_one = 5
number_two = 10

if number_one == 5:
print(1)
elif number_one > 5:
print(2)
elif number_two < 5:
print(3)
elif number_one < number_two:
print(4)
elif number_one != number_two:
print(5)
else:
print(6)

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

height = 65
gender = “female”

if height < 62:
print(“You are below average height”)
elif height > 69:
print(“You are above average height”)
else:
print(“You are average height”)

A

You are average height

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

height = 65
gender = “female”

if height < 62 or (height < 69 and gender == “male”):
print(“You are below average height”)
elif height > 69 or (height > 62 and gender == “female”):
print(“You are above average height”)
else:
print(“You are average height”)

A

You are above average height

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
11
Q

favorite_color = “blue”

if favorite_color != “green”:
print(“But green is the color of grass!”)
if favorite_color == “red”:
print(“I like red, too!”)
if favorite_color == “blue”:
print(“Blue is the best”)
if favorite_color != “yellow”:
print(“But yellow is the color of school buses!”)

A

But green is the color of grass!
Blue is the best
But yellow is the color of school buses!