Select Page

CMIS 102 University of Maryland Function Compute Returns Questions

Question Description

I’m working on a python test / quiz prep and need an explanation to help me study.

See Attachment

Question 1 (10 points

undefined

Which of the following best describes what the function compute returns?

def compute(n):
i = n
sum = 0
while i <= 10:
sum = sum + i
i = i + 1
return sum

Question 1 options:

It returns the sum of integers from n+1 to 10

It returns the sum of integers from n to 10

It returns the sum of integers from n to 9

It returns the sum of integers from n+1 to 9

Question 2 (10 points)

undefined

What would be output by the following statements?

result = None
for value in [8, 3, 91, 13, 49, 19]:
if result is None or value >= result:
result = value
print(result)

Question 2 options:

3

8

91

19

Question 3 (10 points)

undefined

Which of the following while loops will be an infinite loop?

Question 3 options:

i = 10
while i <= 25:
print(i)
i = i + 1

i = 10
while i <= 20:
print(i)
i = i – 1

i = 10
while i > 0:
print(i)
i = i – 1

i = 5
while i >= 15:
print(i)
i = i – 1

Question 4 (10 points)

undefined

Which of the following best describes what the function compute returns?

def compute(values):
result = None
for value in values:
if result is None or value < result:
result = value
return result

Question 4 options:

It returns the largest value in the list values

It returns the smallest value in the list values

It returns the number of elements in the list values

It returns the sum of all the elements in the list values

Question 5 (10 points)

undefined

What would be output by the following statements?

result = 0
for value in [12, 5, 3, 13, 40]:
result = result + 1
print(result)

Question 5 options:

14.7

5

15

73

Question 6 (10 points)

undefined

Which of the following programs would output the largest element in the list named values?

Question 6 options:

values = [13, 65, 11, 34, 58]
largest = None
for value in values:
if largest is None or value < largest:
largest = i
print(largest)

values = [13, 65, 11, 34, 58]
largest = None
for value in values:
if largest is None or value > largest:
largest = value
print(largest)

values = [13, 65, 11, 34, 58]
largest = None
for value in values:
if largest is None or value != largest:
largest = value
print(largest)

values = [13, 65, 11, 34, 58]
largest = None
for value in values:
if largest is None or value == largest:
largest = value
print(largest)

Question 7 (10 points)

undefined

Which of the following programs would output the sum of all the elements in the list [22, 4, 11, 3, 17]?

Question 7 options:

sum = 0
for value in [22, 4, 11, 3, 17]:
sum = value
print(‘Sum:’, sum)

sum = 0
for value in [22, 4, 11, 3, 17]:
sum = sum + value
print(‘Sum:’, sum)

sum = 0
for value in [22, 4, 11, 3, 17]:
sum = 1
print(‘Sum:’, sum)

sum = 0
for value in [22, 4, 11, 3, 17]:
sum = sum + 1
print(‘Sum:’, sum)

Question 8 (10 points)

undefined

What would be output by the following statements?

n = 5
while n >= 2:
print(n + 1)
n = n – 3

Question 8 options:

6
3

6

3

5
4

Question 9 (10 points)

undefined

Which of the following programs will output this sequence of numbers? 2 3 4 5 6

Question 9 options:

n = 2
while n < 6:
print(n)
n = n + 1

n = 2
while n <= 6:
print(n)
n = n + 1

n = 2
while n <= 6:
print(n)
n = n – 1

n = 2
while n < 6:
n = n + 1
print(n)

Question 10 (10 points)

undefinedSaved

Which of the following functions would return the smallest value in a list named numbers passed as a parameter?

Question 10 options:

def minimum(numbers):
smallest = None
for number in numbers:
if smallest is None or number < smallest:
smallest = number
return smallest

def minimum(numbers):
smallest = 0
for number in numbers:
smallest = smallest + number
return smallest

def minimum(numbers):
smallest = None
for number in numbers:
if smallest is None or number > smallest:
smallest = number
return smallest

def minimum(numbers):
smallest = 0
for number in numbers:
if number > 0:
smallest = smallest + 1
return smallest

"Place your order now for a similar assignment and have exceptional work written by our team of experts, guaranteeing you "A" results."

Order Solution Now