AP Comp Sci Unit 5 Test

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

How many return values come out of the function sum? def sum(first, second): result = first + second return result 0 1 2 3

1

How many parameters go into the function sum? def sum(first, second): result = first + second return result 1 0 3 2

2

What is the output of the following code? def quadruple_number(x): quad_x = 4 * x print(quad_x) x = 5 quadruple_number(x) 10 15 20 no output, there is a syntax error

20

What is printed by the following code? def print_numbers(first, second, third): print(first) print(second) print(third) middle = 5 print_numbers(4, middle, 6) 456 4 5 6 4middle6 4 middle 6

4 5 6

Why do we write functions? Make our code easier to understand by giving a readable name to a group of instructions Avoid writing repeated code Make our code reusable All of these

All of these

What does API stand for in computer science? American Petroleum Institute After Paleozoic Index A-frame Pixel Interface Application Programming Interface

Application Programming Interface

True or false: Functions should have parameters. True False

False

Which of the following is true about return values? Functions can have return values, but they are optional. Functions can have more than one return function Functions must have a return function Functions need to return the same number of values that were passed into the function

Functions can have return values, but they are optional.

In which namespace is the variable 'x' defined in the following program? x = 10 def add_nums(): y = 2 z = x + y print z Function namespace Global namespace Object namespace Class namespace

Global namespace

Why do we write functions? I. Make our code easier to understand by giving a readable name to a group of instructions II. Avoid writing repeated code III. Make our code reusable II and III I only I and II I, II, and III

I, II, and III

What is the purpose of a return statement in a function? Returns the value and stops the executing the program Stops executing the function and returns the value Returns the program back to the start of the function and continues to execute statements Returns the value and continues executing rest of the statements, if there are any

Stops executing the function and returns the value

Which of the following is the correct way to create a function in Python? function = my_function() def:my_function() def my_function() my_function()

def my_function()

Which of the following functions successfully returns the number 10? def my_function(): 10 def my_function(10): return def my_function(): return 10 def my_function(): print 10

def my_function(): return 10

Which of the following functions successfully returns double the variable 'number'? def my_function(number): return number*2 def my_function(number*2): return def my_function(): return number def my_function(number): number*2

def my_function(number): return number*2

If added to the program below, which of the following additional functions would not cause an error? x = 10 def add_nums(): y = 2 z = x + y print z def subtract_nums(): z = x - y print z def subtract_nums(): z = z - x print z def subtract_nums(): y = 5 z = x - y print z def subtract_nums(): z = y z = x - y print z

def subtract_nums(): y = 5 z = x - y print z

If we want to draw a circle using our helpful draw_circle function at position (300, 400) with a radius of 40 and color blue, which is the correct function call? As a reminder, here's the function header for draw_circle: def draw_circle(radius, color, x, y) draw_circle(300, 400, 40, Color.blue) draw_circle(300, 400, Color.blue, 40) draw_circle(40, Color.blue, 300, 400) draw_circle(radius, color, x, y)

draw_circle(40, Color.blue, 300, 400)

Consider the code snippet: def print_numbers(first, second, third): print(first) print(second) print(third) print_numbers(12, 17, 65) print_numbers(1, 2, 3) print_numbers(3, 3, 20) What are the names of the parameters? 12, 17, 65 1, 2, 3 3, 3, 20 first, second, third

first, second, third

What are the parameters of the print_numbers function? def print_numbers(first, second, third): print(first) print(second) print(third) first, second, third x, y, z print print_numbers

first, second, third

Do functions need to have parameters? yes no

no

Which statement allows us to return values from functions? break return while function

return

Consider the code snippet: def draw_circle(radius, color, x, y): circle = Circle(radius) circle.set_color(color) circle.set_position(x, y) add(circle) What is the return value for this function? the radius value passed to draw_circle the color passed to draw_circle the x and y coordinates passed to draw_circle this function has no return value

this function has no return value

def quadruple_number(x): quad_x = 4 * x print(quad_x) What is the parameter of the function quadruple_number? x println quad_x none

x


Ensembles d'études connexes

El Conditional Tense. Realidades 3 pag. 352 "You use the conditional in Spanish to express what a person would do or what a situation would be like"

View Set