Programming with Python

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

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 / 2)

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

1

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

1

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

12.4

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

2

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?

3

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)

30

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)

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

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)

FlorenceFernandez

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 center of the circle

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(event))

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

The following code 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?

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 center of the window?

WIDTH / 2, HEIGHT / 2

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?

WIDTH, HEIGHT

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)

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 = int(input("How many apples would you like? "))

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

callback function

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

Which of the following lines of code would be conssidered the highest level of code?

move()

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

num_apples = 20

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))

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

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 = 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? "))

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

All of these choices

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


Conjuntos de estudio relacionados

3.1, 3.2, & 3.3 MCQs to Check for Understanding

View Set

9.1 - Definitions Under The Uniform Securities Act

View Set

Geophysical Methods for Compulsory Question

View Set

10.1 "Cause" & Necessary & Sufficient Conditions

View Set

Vocabulaire préparatoire au DFP B1/DFP AFFAIRES B1

View Set

Ch 5 Commonly Occurring Infections

View Set

Chapter 10: Campaigns and Elections

View Set