跳至主要內容

5.10.1 Functions and Parameters Quiz

AI悦创原创1v1java 1v1高中生Python辅导web 一对一数据结构一对一留学生辅导creanlutheran.org留学生作业辅导1v1java 1v1高中生Python辅导web 一对一数据结构一对一留学生辅导creanlutheran.org留学生作业辅导大约 6 分钟...约 1842 字

Question: 1

In the following code:「D」

size = 20
x = 100
y = 200
ball = Circle(size)
circle.set_position(x, y)

What is the meaning of the x variable?

A. The x coordinate of the left side of a box that would hold the circle

B. The x coordinate of the right edge of the circle

C. The radius of the circle

D. The x position of the center circle

Question: 2

The following program should draw a circle on the screen「D」

def draw_circle(x, y):
    circle = Circle(100)
    circle.set_position(x,  y)

But when we run this code, we don’t see the circle. What is missing?

A. Since we are trying to create a circle, we need to use the create_circle command.

B. The code will have an error since you need to define the color.

C. You need to add the circle with the circle.add() command.

D. You need to add the circle with the add(circle) command.

Question: 3

We want to position a Circle on our screen to be at a random position, but we want to keep the entire shape on the screen. Which of the following will accomplish this given the following function? (Assume SIZE, HEIGHT, and WIDTH are properly defined):「B」

def draw_circle(x, y, radius):
    circle  = Circle(radius)
    circle.set_position(x, y)
    add(circle)

A.

x = random.randint(0,WIDTH)
y = random.randint(0,HEIGHT)
draw_circle(x, y, SIZE)

B.

x = random.randint(SIZE,WIDTH-SIZE)
y = random.randint(SIZE,HEIGHT-SIZE)
draw_circle(x, y, SIZE)

C.

x = random.randint(0,HEIGHT)
y = random.randint(0,WIDTH)
draw_circle(x, y, SIZE)

D.

x = random.randint(SIZE,HEIGHT-SIZE)
y = random.randint(SIZE,WIDTH-SIZE)
draw_circle(x, y, SIZE)

Question: 4

Why do we write functions?「D」

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

A. II and III

B. I only

C. I and II

D. I, II, and III

Question: 5

In the following function print_three_times:「D」

def print_three_times(word):
    print(word)
    print(word)
    print(word)

What is the parameter of the function?

A. print_three_times

B. def

C. print

D. word

Question: 6

What is the output of the following program?

def sum_to(num):
    sum = 0
    for i in range(num+1):
        sum += i
    print(sum)

x = 5
sum_to(x)
print(x)

A.

5
15

B.

15
5

C.

5

D.

15

Question: 7

What is printed by the following program?

def print_numbers(two, one, zero):
    print(two)
    print(one)
    print(zero)

zero = 0
one = 1
two = 2
print_numbers(zero, one, two)

Question: 8

How many parameters go into the function sum, and how many return values come out of the function sum?

def sum(first, second, third):
    result = first + second + third
    print(first)
    print(second)
    print(third)
    return result

A. 3 parameters go in, 1 return value comes out

B. 3 parameters go in, 3 return values come out

C. 1 parameter goes in, 4 return values come out

D. 1 parameter goes in, 1 return value comes out

Question: 9

“It’s a bird! It’s a plane! No, it’s Superman!”「C」
We want to write a function is_superman that takes in two parameters is_bird and is_plane and returns True if it is in fact Superman, and False otherwise.

If it’s not a bird and it’s not a plane, it must be Superman.

Which of the following functions is the correct implementation of is_superman?

A.

def is_superman(is_bird, is_plane):
    return is_bird or is_plane

B.

def is_superman(is_bird, is_plane):
    return not is_bird or not is_plane

C.

def is_superman(is_bird, is_plane):
    return not is_bird and not is_plane

D.

def is_superman(is_bird, is_plane):
    return is_bird and is_plane

Question: 10

What is printed by the following program?

def product(x, y):
    return x * y

def difference(x, y):
    return x - y

x = 2
y = 5
value1 = product(x, y)
value2 = difference(y, x)

result = difference(value1, value2)
print(result)

A. 7

B. -7

C. 13

D. -13

Question: 11

In the following code:

import random

MAX_NUMBER = 10

def sum(x, y):
    result = x + y

    #Point A

    return result


num1 = random.randint(0, MAX_NUMBER)
num2 = random.randint(0, MAX_NUMBER)
print( sum(num1, num2) )

Which variables exist at point A? In other words, which variables are in scope at point A? Which variables could you type at point A and the program would still work?

A. result only

B. result, x, and y

C. result, x, y, num1, num2, and MAX_NUMBER

D. result, num1, num2, and MAX_NUMBER

E. result, x, y, and MAX_NUMBER

Question: 12

True or False: Functions must have parameters.

A. True

B. False

Question: 13

Which statement allows us to return values from functions?

A. break

B. return

C. while

D. function

Question: 14

Which of the following is true for an API?

I. Allows different devices to connect with each other

II. Allows for Interactivity between devices and software

III. Messenger program that takes requests and delivers the response back to the user

IV. Allows the creation of applications that access the features or data of an operating system, application, or other services

V. Specifies how software components should interact

VI. Used when programming graphical user interface (GUI) components

A. I, II, III, IV, V, and VI

B. II, III, and V

C. VI only

D. I, IV, and Vi

Question: 15

What does API stand for in computer science?

A. American Petroleum Institute

B. After Paleozoic Index

C. A-frame Pixel Interface

D. Application Programming Interface

Question: 16

What is the purpose of a return statement in a function?

A. Returns the value and stops executing the program

B. Stops executing the function and returns the value

C. Returns the program back to the start of the function and continues to execute statements

D. Returns the value and continues executing rest of the statements, if there are any

Question: 17

Which of the following is true about return values?

A. Functions can have return values, but they are optional.

B. Functions can have more than one return value

C. Functions must have a return value

D. Functions need to return the same number of values that were passed in to the function

Question: 18

Consider the following code snippet. What is returned and printed for the value of a?

def mystery(x, y):
    if x < y:
        return x
    else:
        return y

a = mystery(10, 14)
b = mystery(82, 28)

print(a)
print(b)

A. 10

B. 14

C. 28

D. 82

Question: 19

What does the mystery function do in the code snippet below?

def mystery(x, y):
    if x < y:
        return x
    else:
        return y

a = mystery(10, 14)
b = mystery(82, 28)

print(a)
print(b)

A. returns the smaller of two values passed to it

B. returns the larger of the two values passed to it

C. mystery does nothing because there is a syntax error

D. mystery does nothing because there is a logical error

Question: 20

Consider the following code snippet:

def mystery1(x):
    result = x + 1
    return result

def mystery2(x, y):
    result = x + y
    return result

def mystery3(x):
    result = x * x
    return result

What would the following print?

y = mystery2(12)
print(y)

A. 13

B. This would generate an error

C. 144

D. This would not print anything

Question: 21

Which of the following functions will correctly return True if it is passed an odd integer value for x?

I.

def is_odd (x) :
     return x % 2 == 1

II.

def is_odd (x) :
     return x / 2 == 1 

III.

def is_odd (x) :
    if x % 2 == 1:
        return True
    else:
        return False

A. I, II, and III

B. II only

C. I and II only

D. I and III only

Question: 22

Consider the following code snippet:

WIDTH = 300
HEIGHT = 300

def draw_circle(radius, color, x, y):
    circle = Circle(radius)
    circle.set_color(color)
    circle.set_position(x, y)
    add(circle)

draw_circle(40, "red" 100, 300)
draw_circle(50, "green", 50, 100)
draw_circle(70, "blue", WIDTH/2, HEIGHT/2)
draw_circle(25, "yellow", WIDTH/2, 300)

In the third call to draw_circle(), what values are passed to the coordinates of the center of the circle?

A. 100, 300

B. 50, 100

C. 150, 150

D. 200, 300

Question: 23

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?

A. the radius value passed to draw_circle

B. the color passed to draw_circle

C. the x and y coordinates passed to draw_circle

D. this function has no return value

Question: 24

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 names of the parameters?

A. 12, 17, 65

B. 1, 2, 3

C. 3, 3, 20

D. first, second, third

Question: 25

Which of the following is the correct way to create a function in Python?

A. function = my_function()

B. def:my_function()

C. def my_function():

D. my_function()

公众号:AI悦创【二维码】

AI悦创·编程一对一

AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh

C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh

方法一:QQopen in new window

方法二:微信:Jiabcdefh

上次编辑于:
贡献者: AndersonHJB
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度