APCSP - Unit 4 CodeHS Flashcards
what are valid values for a boolean?
True, False
after the following code runs, what is the value of is_weekend?
is_saturday=True
is_sunday=False
is_weekend=is_saturday or is_sunday
True
what symbol represents and operator in Python?
and
what symbol represents or operator in Python?
or
what is the proper way to compare if two values are equal in a boolean expression in Python?
==
what is the proper operator for “not equals” in Python?
!=
determine whether the following expression would evaluate to true or false:
7=6 OR 8≥4
True
determine whether the following expression would evaluate to true or false:
(9≠13 AND 12<4) OR 15<9
False
which of the following Boolean expressions is equivalent to the expression
a AND (b OR c)
(a AND b) OR (a AND c)
which of the following Boolean expressions is equivalent to the expression
(a OR b) AND NOT (c OR d)
(a OR b) AND (NOT c) AND (NOT d)
which of the following are equivalent to the code block?
IF (NOT (rainy OR tooCold))
{
DISPLAY(“It’s a good beach day”)
}
IF ((NOT rainy) AND (NOT tooCold)))
{
DISPLAY(“It’s a good beach day”)
}
how can we set up animate to be called every time a key on the keyboard is pressed down?
def animate(event):
ball.move(5, 5)
add_key_down_handler(animate)
how many times will the following program print “hello”?
for i in range(5):
print(“hello”)
5
what will be the last number to print to the screen before the program finishes?
for i in range(10):
if i % 2 == 0:
print(i)
else:
print(2 * i)
18
how many times will the following code print “hello”?
for i in range(3, 8):
print(“hello”)
5
how many times will the following code print “hello”?
for i in range(0, 8, 2):
print(“hello”)
4
why do we use constant variables?
- to avoid having “magic numbers” (unique numbers with unexplained meaning) in our code
- to give values a readable names so that their purpose is clear
- to let us easily change the behavior of our program by only having to change a value in one place
what will be the value of sum after this code runs?
START = 1
END = 5
sum = 0;
for i in range(START, END):
sum += i
10
which returns a random number between 1 and 10?
random.randint(1,10)
how many possible values can the following code return?
random.choice([1,5])
2
how many times will this program print “hello”?
i = 50
while i < 100:
print(“hello”)
this code will loop infinitely
how many times will this program print “hello”?
i = 10
while i > 0:
print(“hello”)
i -= 1
10