Question
I need help with these practice questions please... 1. Which of the following is the best reason fordividing a program into functions? A. Using multiple
I need help with these practice questions please...
1. Which of the following is the best reason fordividing a program into functions?
A. Using multiple functions reduces the possibility of codereuse
B. Increasing the number of functions in a program greatlyincreases the speed of the program
C. By subdividing a program into multiple functions, it makesthe program more secure
D. Because functions can eliminating repetitive code, if achanges is needed, it is only necessary to make it in one place
2. What would be output by the following functiondefinitions and function calls?
def print_stars():
print('***')
def print_crosses():
print('xxx')
print_crosses()
print_stars()
A.***
xxx
B. *x*x*x
C. x*x*x*
D. xxx
***
3. Which of the following function calls would convertthe integer 185 into the string '185'?
A. str(185)
B. string(185)
C. convert(185)
D. to_string(185)
4. What would be output by the following functiondefinition and function call?
def make(x, y):
if x >= y - 2:
print(x - 1)
else:
print(y + 6)
make(10, 8)
A. 7
B. 9
C. 14
D. 16
6. What would be output by the followingstatements?
x = max(min(5, 3), 4, 2)
print(x)
A. 5
B. 4
C. 2
D. 3
8. What would be output by the following functiondefinition and function call?
def divide(x, y):
if x % y == 1:
return x // 3
else:
return y // 2
print(divide(11, 5))
A. 2.5
B. 3
C. 5.5
D. 1
9. Which of the following functions woulddisplay Divisible ifthe second parameter evenly divides the first parameter and printsnothing otherwise?
A. def divides(x, y):
if x % y == 0:
print('Divisible')
B. def divides(x, y):
if x // y:
print('Divisible')
C. def divides(x, y):
if x % y:
print('Divisible')
D. def divides(x, y):
if x // y == 0:
print('Divisible')
10. Which of the following functions would return thesum of its two parameters if they are both even numbers and theirproduct otherwise?
A. def sum_product(x, y):
if x % 2 == 0 and y % 2 == 0:
return x * y
else:
return x + y
B. def sum_product(x, y):
if x % 2 == 0 or y % 2 == 0:
return x + y
else:
return x * y
C. def sum_product(x, y):
if x % 2 == 0 and y % 2 == 0:
return x + y
else:
return x * y
D. def sum_product(x, y):
if x % 2 == 0 or y % 2 == 0:
return x * y
else:
return x + y
Step by Step Solution
3.49 Rating (162 Votes )
There are 3 Steps involved in it
Step: 1
Answer 1 D Because functions can eliminating repetitive code if a changes is needed it is only necessary to make it in one place 2 D xxx 3 A str185 4 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started