Unit 2 AP CSP Test

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

Consider the following code segment. a ← 1 b ← a a ← 2 What value is stored in variable b? 1 2 a 3

1

What is printed to the screen when the following program is run? num = 13 % 3 print(num) 1 2 3 4

1

What does the following Python program print? x = 9 + 6 / 3 * 2 - 1 print(x) 9 12 15 21

12

What will be printed from the following: x = 4 * 3 + 2 / 5 print(x) 12.4 12 13.6 4

12.4

What will the following code segment evaluate to? a = 10 b = 5 c = 2 expression = ((a - b) * c) % 3 print(expression) 1 3 5 10

1

What will the following code segment evaluate to? a ← 10 b ← 5 c ← 2 expression = (a - b) * c DISPLAY(expression) 0 10 -10 -5

10

What will the following code segment evaluate to? a ← 9 b ← 5 c ← 4 expression = a + b * c DISPLAY(expression) 29 56 29.0 56.0

29

What is printed to the screen if the user enters '5' when the following program is run? user_num = int(input("Enter your favorite number: ")) calculated_num = user_num * user_num + user_num print(calculated_num) 5 25 30 50

30

Which of the following could be considered a computer? Smart phone Digital cofee maker Cars All of these choices

All of these choices

What is the output of the following program: (Assume the user enters 'Florence' then 'Fernandez'.) first_name = input("What is your first name? ") last_name = input("What is your last name? ") whole_name = first_name + last_name; print (whole_name) Fernandez Florence Florence Fernandez FlorenceFernandez Florence Fernandez

FlorenceFernandez

In a graphics canvas with a size of WIDTH and a height of HEIGHT, what are the coordinates of the center of the window? WIDTH, HEIGHT WIDTH / 2, HEIGHT / 2 0, 0 HEIGHT / 2, WIDTH / 2

WIDTH / 2, HEIGHT / 2

On the AP exam, INPUT() is used to accept a value from the user, and DISPLAY() is used to display a value. Values that are displayed are NOT started on a new line, but a space is added after the value. Consider the code segment below. DISPLAY ("What is your name?") name ← INPUT () DISPLAY ("Hello") DISPLAY (name) What is displayed as a result if the user inputs "Rowan" then hits enter into the program? What is your name? Rowan Hello Rowan What is your name? Rowan Hello Rowan What is your name? Rowan HelloRowan Hello Rowan

What is your name? Rowan Hello Rowan

You are splitting up all of your apples equally between 3 people. Which statement below will calculate how many apples will be left over? left_over = num_apples / 3 left_over = 3 / num_apples left_over = num_apples % 3 left_over = 3 % num_apples

left_over = num_apples % 3

Which of the following lines of code would be considered the highest level of code? 10110011010011101010 move() movl $1, %eax def move():

move()

What is the proper keyword to print to the screen? write println print output

print

What function do you need to call to ask the user of the program to enter text? input read text print

input

What type is the following variable? x = "Hi there" float integer boolean string

string

Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style? user_age User_Age user_Age userAge

user_age

Which of the following is NOT a program that will produce the following output? hellohellohello var = "hello" * 3 print(var) var = "hello" + "hello" + "hello" print(var) var = "hello" print(var) print(var) print(var) num_times = 3 var = "hello" * num_times print(var)

var = "hello" print(var) print(var) print(var)

Which of the following Python programs will not run? x = 4 print("x") x = 4 y = "hi" print(x + y) x = 4.6 y = "hi" print(str(x) + y) x = 4 print(x)

x = 4 y = "hi" print(x + y)

In the following code: size = 20 x = 100 y = 200 ball = Circle(size) ball.set_position(x, y) What is the meaning of the x variable? The x coordinate of the left side of a box that would hold the circle The x coordinate of the right edge of the circle The radius of the circle The x coordinate of the center of the circle

The x coordinate of the center of the circle

If you wanted to use the following code to draw a circle to the canvas with the radius, and x and y coordinates given by the user, how would you ask for this information? circle = Circle(radius) circle.set_position(x, y) x = input("What is the x coordinate? ") y = input("What is the y coordinate? ") radius = input("What is the radius of the circle? ") x = int(input("What is the x coordinate? ")) y = int(input("What is the y coordinate? ")) radius = int(input("What is the radius of the circle? ")) x = input("What is the x coordinate? ") y = input("What is the y coordinate? ") radius = int(input("What is the radius of the circle? ")) x = int(input("What is the x coordinate? ")) y = int(input("What is the y coordinate? ")) radius = input("What is the radius of the circle? ")

x = int(input("What is the x coordinate? ")) y = int(input("What is the y coordinate? ")) radius = int(input("What is the radius of the circle? "))

What will the following code segment evaluate to? a ← 10 b ← 5 c ← 2 expression = a / b * c DISPLAY(expression) 1 4 2.5 25

4

On the AP exam, the ← operator is used for variable assignment. For example, a ← 10 assigns the value 10 to the variable a. The value stored in a variable will always be the most recent value assigned. Consider the following code segment. a ← 12 b ← 3 c ← 27 a ← b b ← c c ← a What value is stored in variable c? 12 3 27 c is undefined

3

What is a callback function? A function passed to an event handler that is called every time a certain event happens A function called at the bottom of the program A function that is never called A function called every 20 milliseconds

A function passed to an event handler that is called every time a certain event happens

What does the following program do? radius = int(input("What is the radius of the circle? ")) circle = Circle(radius) circle.set_position(radius, radius) add(circle) Draws a circle to the center of the canvas with size based on user inputted value Draws a circle on the canvas with the center positioned at the coordinate (0,0) Draw a circle on the canvas that is radius distance in the x and y direction from the top left corner The program contains an error.

Draw a circle on the canvas that is radius distance in the x and y direction from the top left corner

What does the following code snippet do? Choose the best answer. def click(event): size = 20 circle = Circle(size) circle.set_position(event.x, event.y) add(circle) add_mouse_click_handler(click(even)) This code snippet randomly places black circles on the screen. This code snippet places a black circle on the screen with a radius of 10 in every place that the mouse is clicked. This code snippet places a black circle on the screen with a radius of 20 in every place that the mouse is clicked. This code snippet has an error and will not do anything.

This code snippet has an error and will not do anything.

You want to read input from the user to know how many apples they would like to buy. Which statement should you use to read in a number from the user? apples_to_buy = input("How many apples would you like? ") apples_to_buy = print("How many apples would you like? ") apples_to_buy = int(input("How many apples would you like? ")) apples_to_buy = input_int("How many apples would you like? ")

apples_to_buy = int(input("How many apples would you like? "))

What does the following Python program print? x = "I am" y = 6 z = "feet tall" print(x) print(y) print(z) I am 6 feet tall I am6feet tall I am 6 feet tall x y z

I am 6 feet tall

The following program should draw a circle on the screen. def draw_circle(x, y, radius): circle = Circle(radius) circle.set_position(x, y) But when we run this code, we don't see the circle. What is missing? Since we are trying to create a circle, we need to use the create_circle command. The code will have an error need to define the position when you create the the circle To add the circle to the canvas, you need to use the circle.add() command To add the circle to the canvas, you need to use the add(circle) command

To add the circle to the canvas, you need to use the add(circle) command

In a graphics canvas with a size of WIDTH and a height of HEIGHT, what are the coordinates of the bottom right corner of the window? 0, 0 - HEIGHT / 2, WIDTH / 2 HEIGHT, WIDTH WIDTH, HEIGHT

WIDTH, HEIGHT

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()) add_key_down_handler("animate") add_key_down_handler(animate(event)) add_key_down_handler(animate)

add_key_down_handler(animate)

Suppose we've written a function draw_circle that we want to call every time the mouse is clicked. How can we do this? add_mouse_click_handler(draw_circle(x, y)) add_mouse_click_handler("draw_circle") add_mouse_click_handler(draw_circle) add_mouse_click_handler(draw_circle())

add_mouse_click_handler(draw_circle)

Suppose we've written a function draw_square that we want to call every time the mouse is clicked. How can we do this? add_mouse_click_handler(draw_square) draw_square(on_mouse_click) add_mouse_click_handler(draw_square(x, y)) add_mouse_click_handler(draw_square(event))

add_mouse_click_handler(draw_square)

To ask the user of the program for a number, which function should you use? input int text input inside of a int( ) function

input inside of a int() function

Which of the following print statements is written correctly? print "Hello World" println("Hello World") print("Hello World") print(Hello World)

print("Hello World")

If you were given the following variables: distance = 2 time = 30 What line of code would print the speed in km/hr if the distance is given in km and the time is given in minutes? (Speed = distance/time) print(distance/(time/60)) print(distance/time) print(distance*(time*60)) print(distance*time)

print(distance/(time/60))

On the AP exam, the ← operator is used for variable assignment. For example, a ← 10 assigns the value 10 to the variable a. Consider the following code segment. a ← 10 b ← 5 c ← a + b What is stored in variable c? 10 5 15 50

15

On the AP Exam, the modulus operator is denoted by MOD. The MOD operator has the same precedence as the * and / operators. What will c evaluate to in the following code segment? a ← 18 b ← 4 c ← a MOD b 4 2 18 8

2

On the AP Exam, the modulus operator is denoted by MOD. The MOD operator has the same precedence as the * and / operators. What will c evaluate to in the following code segment? a ← 17 b ← 5 c ← a MOD b c = 2 c = 3.4 3 5

c = 2

Choose the best response: A function passed to an event handler that is called every time a certain event happens is called a _______. parameterized function. return function. callback function. generator function.

callback function.

If a user enters a diameter value in the variable diameter, how would we use this to draw the correct sized circle? circle = Circle(diameter) circle = Circle(diameter, diameter) circle = Circle(diameter / 2) "" circle = Circle(diameter * 2) "`

circle = Circle(diameter / 2)

What are the coordinates of the top right corner of the screen? 0, 0 0, get_width() get_width(), 0 get_width(), get_height()

get_width(), 0

A store has 20 apples in its inventory. How can you store this information in a Python variable? num_apples == 20 20 = num_apples num_apples = 20 num apples = 20

num_apples = 20

On the AP exam, INPUT() is used to accept a value from the user and DISPLAY() is used to display a value. Values that are displayed are NOT started on a new line but do contain a space following the value printed. What will display after running the following code? a ← "Welcome!" DISPLAY (a) b ← "‎¡Hola!" DISPLAY (b) a ← b b ← "Bonjour!" DISPLAY (a) DISPLAY (b) Welcome! ‎¡Hola! ‎¡Hola! Bonjour! Welcome! ‎¡Hola! ‎¡Hola! Bonjour! Welcome! ‎¡Hola! Welcome! Bonjour! Welcome! ‎¡Hola! ‎Welcome! Bonjour!

Welcome! ‎¡Hola! ‎¡Hola! Bonjour!

Which of the following operations will output a value of 5? 11 % 6 11/2 float(11)/2 2 + 3 * 2

11 % 6

In the following code, we create a circle and add it to the screen. What is the meaning of the x and y variables? x = 20 y = 20 circ = Circle(30) circ.set_position(x, y) The position of the center of the circle. The position of the bottom left of the circle. The position of the top left of the circle The radius of the minor and major axis of the oval.

The position of the center of the circle


Conjuntos de estudio relacionados

Taylor's Fundametnals PrepU Ch. 45 Sensory Functioning

View Set

U.S. Government Final Exam review

View Set

Workforce Planning & Employment section 2-7

View Set

Microbiology Chapter 9 Physical and Chemical Control of Microbes

View Set

Chapter 10 - Interest in Real Estate - Mini Quiz

View Set

Federal Tax Considerations for Accident and Health Insurance

View Set

Performance by client needs; Coordinated Care

View Set

Grammar: Fragments, Run-ons, and Comma Splices Practice and Quiz

View Set