3.9.1 Programming with Python Quiz

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/24

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

25 Terms

1
New cards

The following code should draw a circle on the screen.

def draw_circle(x, y, radius):

circle = Circle(radius)

circle.set_position(x, y)

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

2
New cards

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

3
New cards

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

4
New cards

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

5
New cards

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

6
New cards

What is printed to the screen when the following program is run?

num = 13 % 3

print(num)

1

7
New cards

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

8
New cards

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

9
New cards

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)

10
New cards

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

num_apples = 20

11
New cards

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

12
New cards

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

13
New cards

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

14
New cards

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

15
New cards

In the following code:

size = 20

x = 100

y = 200

ball = Circle(size)

ball.set_position(x, y)

The x coordinate of the center of the circle

16
New cards

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.

17
New cards

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)

18
New cards

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)

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

19
New cards

What will be printed from the following:

x = 4 * 3 + 2 / 5

print(x)

12.4

20
New cards

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

move()

21
New cards

Which of the following could be considered a computer?

all of these choices

22
New cards

Question: 22

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

23
New cards

What will the following code segment evaluate to?

a = 10

b = 5

c = 2 expression = ((a - b) * c) % 3

print(expression)

1

24
New cards

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 your name? Rowan

Hello Rowan

25
New cards

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