AP Comp Sci 4.1-4.8 Quiz

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following is not a valid value for a boolean? True False yes All of the above are all valid

yes

What symbol represents the or operator in Python? OR or | ||

|

What is the proper operator for "not equals" in Python? =! != ~= NOT EQUALS

!=

An office building has two floors. A computer program is used to control an elevator that travels between the two floors. Physical sensors are used to set the following Boolean variables. The elevator moves when the door is closed and the elevator is called to the floor that it is not currently on. Which of the following Boolean expressions can be used in a selection statement to cause the elevator to move.

(onFloor1 AND callTo2) OR (onFloor2 AND callTo1)

In the following code, 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(0, 8, 2): print("hello")

4

How many times will the following program print "hello"? for i in range(5): print("hello")

5

How many times will the following code print "hello"? for i in range(3, 8): print("hello") why?

5 because i will start at 3, then go to 4, 5, 6, and 7, but stop before 8. It is a total of 5 times.

What is the proper way to compare if two values are equal in a boolean expression in Python? = == EQUALS is

==

Consider the code segment below.If the variables onTime and absent both have the value false, what is displayed as a result of running the code segment?

Better late than never.

In the following code block, assume that the variables rainy and tooCold are boolean. IF (NOT (rainy OR tooCold)) { DISPLAY("It's a good beach day") } Which of the following are equivalent to the above code block? IF (( NOT rainy) OR (NOT tooCold)) { DISPLAY("It's a good beach day") } IF (( NOT rainy) AND tooCold) { DISPLAY("It's a good beach day") } IF (( NOT rainy) AND (NOT tooCold)) { DISPLAY("It's a good beach day") } IF (rainy AND tooCold) { DISPLAY("It's a good beach day") }

IF (( NOT rainy) AND (NOT tooCold)) { DISPLAY("It's a good beach day") }

A summer camp offers a morning session and an afternoon session. The list morningList contains the names of all children attending the morning session, and the list afternoonList contains the names of all children attending the afternoon session. Only children who attend both sessions eat lunch at the camp. The camp director wants to create lunchList, which will contain the names of children attending both sessions. The following code segment is intended to create lunchList, which is initially empty. It uses the procedure IsFound (list, name), which returns true if name is found in list and returns false otherwise. You also will you the APPEND(list, name) procedure which will add a name to a given list. FOR EACH child IN morningList { <MISSING CODE> } Which of the following could replace <MISSING CODE> so that the code segment works as intended?

IF (IsFound (afternoonList, child)) { APPEND (lunchList, child) }

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

We've written a function animate that moves a ball across the screen like this: def animate(event): ball.move(5, 5) How can we set up animate to be called every time a key on the keyboard is pressed down?

add_key_down_handler(animate)

What symbol represents the and operator in Python? AND and & &&

and

Which of the following programs will not print anything? x = True if x: print("hi") if False: print("hi") x = False if x: print("hi") else: print("hello") if False: print ("hi") else: print("Hello")

if False: print("hi")

Assume you are writing a program, and you have a boolean variable called b, defined like so: b = True Pick the correct if statement to follow the code above. The if statement should be correct Python, and the body of the if statement should only run if b is True. if b: print("b is True!") if b: print("b is True!") Python if True: print(b) Python if True: print(b)

if b: print("b is True!")


Conjuntos de estudio relacionados

Everfi Module 2 - Employment and Taxes

View Set

Conservation of Energy Review Quiz

View Set

A&P 2 - Chapter 17 Group 1: modules 17.1-17.3

View Set

NMNC 1110 EAQ 10: Safety and Infection Control (Mastery)

View Set

Quiz 3: Understanding Your Family

View Set

Fundamentals Chapter 17 PREPU Questions

View Set

PN Learning System Medical-Surgical: Gastrointestinal Practice Quiz

View Set