Which of the following functions would return 1 if the first parameter is greater than the second and -1 otherwise?

Question 1 options:

def greater(x, y):

if x – y < 0:
return 1
else:
return -1
def greater(x, y):
if y > x:

return 1

else:

return -1

def greater(x, y):

if x >= y:

return -1

else:

return 1

def greater(x, y):

if x > y:

return 1

else:

return -1

Question 2 (10 points)

Which of the following functions would display Percentage if the sum of the two parameters equals one hundred and prints nothing otherwise?

Question 2 options:

def divides(x, y):

if x + y = 100:

print(‘Divisible’)

def percent(x, y):

if x + y == 100:

print(‘Percentage’)

def percent(x, y):

if x % y == 100:

print(‘Percentage’)

def percent(x, y):

if x + y >= 100:

print(‘Percentage’)

Question 3 (10 points)

What would be output by the following function definition and function call?

def decrement(x, y):

if x >= 0 or y <= 0:
return x + 3
else:
return y + 1
print(decrement(4, 1))
Question 3 options:
2
5
4
7
Question 4 (10 points)
Which of the following is the best reason for dividing a program into functions?
Question 4 options:
Functions can make a program smaller by eliminating repetitive code
Increasing the number of functions in a program greatly increases the speed of the program
Using multiple functions reduces the possiblity of code reuse
By subdividing a program into multiple functions, it makes the program more secure
Question 5 (10 points)
What would be output by the following statements?
import math
x = math.sqrt(9)
print(x)
Question 5 options:
81.0
18.0
21.0
3.0
Question 6 (10 points)
What would be output by the following statements?
x = len('abc')
y = len('xyz\n')
print(x, y)
Question 6 options:
3 5
3 4
3 3
5 6
Question 7 (10 points)
Which of the following function calls would return the largest of the three values: 11, 8, 54?
Question 7 options:
min(11, 8, 54)
max(11, 8, 54)
maximum(11, 8, 54)
largest(11, 8, 54)
Question 8 (10 points)
Which of the following is the syntactically correct definition of a function to print the string welcome?
Question 8 options:
def welcome()
print('welcome')
function print_welcome():
print('welcome')
def print_welcome():
print('welcome')
def print:
print('welcome')
Question 9 (10 points)
What would be output by the following function definitions and function calls?
def print_numbers():
print('123')
def print_letters():
print('abc')
print_numbers()
print_letters()
print_numbers()
Question 9 options:
123
abc
123
abc
123
123
abc
abc
123
abc
123
abc
Question 10 (10 points)
What would be output by the following function definition and function call?
def select(x, y):
if x - 1 != y:
print(x / 2)
else:
print(y // 6)
select(12, 9)
Question 10 options:
1
6.0
4.5
1.5