Scripting Exam 2

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

19) Given the following function. To change the function to return the product instead of the sum, how many lines of code need to be changed? def calculate(a, b): ----return a + b print(calculate(3, 4)) print(calculate(5, 2)) print(calculate(6, 7)) a. 1 b. 2 c. 3 d. 4

a. 1

17) _____ allows a function or operator to perform different tasks depending on the types of the arguments or operands. a. Polymorphism b. Static typing c. Type declaration d. Prototyping

a. Polymorphism

15) What is the result when the program is executed? def add(x, y): ----return x + y print('Begin test') s = add('hello', 5) print(s) print('End test') a. The program outputs 'Begin test', then an error is generated, and the program exits. b. An error is generated before anything is printed. c. The program outputs 'Begin test', followed by 'hello5', followed by 'End test' d. The program outputs 'Begin test', followed by 'End test', and no other text is printed.

a. The program outputs 'Begin test', then an error is generated, and the program exits.

7) Which variable can be used in place of XXX in the following code? def fahrenheit_to_celsius(f): ----fraction = 5 / 9 ----c = (f - 32) * fraction ----print(c) degrees = float(input('Enter degrees in Fahrenheit: '))fahrenheit_to_celsius(XXX) a. degrees b. f c. c d. fraction

a. degrees

16) Which term describes how Python assigns the type of a variable? a. dynamic typing b. static typing c. quick typing d. random typing

a. dynamic typing

12) Which XXX will display one more than half of the smallest value of w1, w2, and w3? def min_value(a, b, c): ----if a <= b and a <= c: --------return a ----elif b <= a and b <=c: --------return b ----else: --------return c w1 = 7 w2 = 3 w3 = 12 y = XXX print(y) a. min_value(w1, w2, w3)/2 + 1 b. min_value(w1+1, w2+1, w3+3)/2 c. min_value()/2 + 1, w1, w2, w3 d. min_value: w1, w2, w3() /2 + 1

a. min_value(w1, w2, w3)/2 + 1

4) In the following code, the variable size is the function's _____. def print_square_area(size): area = size * size ----print("A square of size {} has area {}".format(size, area)) s = float(input('Enter size of square: ')) print_square_area(s) a. parameter b. argument c. property d. value

a. parameter

13) Which statement uses the square() function to assign the variable t with 16? Note that 16 = 2^4 = (2^2)^2 def square(x): ----return x * x a. t = square(square(2)) b. t = square(2) + square(2) c. t = square(2), square(2) d. t = square(4) * square(2)

a. t = square(square(2))

6) What is output? def calc(num1, num2): ----print(1 + num1 + num2, end=' ') calc(4, 5) calc(1, 2) a. 9 3 b. 10 4 c. 145 112 d. 4, 5, 1, 2

b. 10 4

20) How does the given function improve the code versus if no function was present? def fahrenheit_to_celsius(fahrenheit): ----return (fahrenheit - 32.0) * 5.0 / 9.0 fahrenheit = float(input()) c1 = fahrenheit_to_celsius(fahrenheit); c2 = fahrenheit_to_celsius(32.0); c3 = fahrenheit_to_celsius(72.0); a. The use of the function makes the program run faster b. The use of the function decreases redundant code c. The use of the function reduces the number of variables in the code d. The function does not improve the code

b. The use of the function decreases redundant code

5) In the following code, the variable val is the function call's _____. def print_square_area(size): ----area = size * size ----print("A square of size {} has area {}".format(size, area)) val = float(input('Enter size of square: ')) print_square_area(val) a. parameter b. argument c. property d. value

b. argument

14) Which of the following lines of code isnotvalid, given the definitions of the cubed() and display() functions? def cubed(x): ----return x * x * x def display(x): ----print(x) a. y = cubed(2.0) b. cubed(x) = 8.0 c. display('Test') d. display(cubed(2.0))

b. cubed(x) = 8.0

2) The code that includes the keyword "def" is called a _____. a. function call b. function definition c. function reference d. function constructor

b. function definition

1) Which XXX causes the program to output the message "Hello!"? def print_message(): ----print('Hello!')XXX a. print_message b. print_message() c. def print_message() d. print_message('Hello!')

b. print_message()

11) Which XXX is valid for the following code? def calc_sum(a, b): ----return a + b XXX print(y) a. y = calc_sum() b. y = calc_sum(4, 5) c. y = calc_sum(4 + 5) d. calc_sum(y, 4, 5)

b. y = calc_sum(4, 5)

3) After a function's last statement is executed, the program returns to the next line after the _____. a. import statement b. function definition c. function call d. start of the program

c. function call

9) Which of the following is true? a. A function must have exactly one return statement, or no return statement at all. b. A function must always have at least one return statement. c. A function can only return strings and numbers, not lists or dictionaries. d. A function can have any number of return statements, or no return statement at all.

d. A function can have any number of return statements, or no return statement at all.

18) Which of the following isnota reason to use functions? a. To avoid writing redundant code b. To improve code readability c. To support modular development d. To make the code run faster

d. To make the code run faster

8) Which correctly calls the add() function? def add(a, b, c): ----print(a + b + c) a. add(2 4 6) b. add(2 + 4 + 6) c. add(2; 4; 6) d. add(2, 4, 6)

d. add(2, 4, 6)

10) Which XXX completes the find_smallest() function? def find_smallest(a, b, c): ----if a <= b and a <= c: --------smallest = a ----elif b <= a and b <= c: --------smallest = b ----elif c <= a and c <= b: --------smallest = c ----XXX result = find_smallest(7, 4, 8) print(result) a. return a b. return b c. return c d. return smallest

d. return smallest


Ensembles d'études connexes

Prop & Casualty Insurance Basics

View Set

Chapter 07: Legal Dimensions of Nursing Practice (2)

View Set

Urinary Tract Infection in the Older Adult

View Set

Stat CH 1 Homework 1.1a Sampling and Parameters Study

View Set