Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help answering these practice questions please... 1 Which of the following functions would return the largest value in a list namednumberspassed as a

I need help answering these practice questions please...

1 Which of the following functions would return the largest value in a list namednumberspassed as a parameter?

A. def maximum(numbers):

largest = 0

for number in numbers:

largest = largest + number

return largest

B. def maximum(numbers):

largest = None

for number in numbers:

if largest is None or number > largest:

largest = number

return largest

C. def maximum(numbers):

largest = None

for number in numbers:

if largest is None or number < largest:

largest = number

return largest

D. def maximum(numbers):

largest = 0

for number in numbers:

if number > 0:

largest = largest + number

return largest

2 What would be output by the following statements?

result = 0

for value in [11, 21, 7, 23, 20, 8]:

result = result + value

print(result)

Question 2 options:

A. 23

B. 15

C. 6

D. 90

3 Which of the following programs would output the largest element in the list[12, 7, 94, 3, 89]?

A. largest = None

for value in [12, 7, 94, 3, 89]:

if largest is None or value == largest:

largest = value

print(largest)

B. largest = None

for value in [12, 7, 94, 3, 89]:

if largest is None or value >= largest:

largest = value

print(largest)

C. largest = None

for value in [12, 7, 94, 3, 89]:

if largest is None or value != largest:

largest = value

print(largest)

D. largest = None

for value in [12, 7, 94, 3, 89]:

if largest is None or value < largest:

largest = value

print(largest)

4 What would be output by the following statements?

result = None

for value in [5, 1, 11, 19, 79, 13]:

if result is None or value > result:

result = value

print(result)

A. 13

B. 79

C. 5

D. 1

5 Which of the followingwhileloops will be an infinite loop?

A. i = 10

while i >= 0:

print(i)

i = i + 1

B. i = 10

while i < 20:

print(i)

i = i + 1

C. i = 10

while i <= 0:

print(i)

i = i + 1

D. i = 10

while i >= 0:

print(i)

i = i - 1

6 Which of the following programs would output the sum of all the elements in the list namedvalues?

A. values = [2, 67, 31, 18, 12]

sum = 0

for value in values:

sum = value

print('Sum:', sum)

B. values = [2, 67, 31, 18, 12]

sum = 0

for value in values:

sum = sum + value

print('Sum:', sum)

C. values = [2, 67, 31, 18, 12]

sum = 0

for value in values:

sum = 1

print('Sum:', sum)

D. values = [2, 67, 31, 18, 12]

sum = 0

for value in values:

sum = sum + 1

print('Sum:', sum)

7 Which of the following programs will output this sequence of numbers?2 5 8

A. n = 2

while n <= 8:

print(n)

n = n + 3

B. n = 2

while n < 8:

print(n)

n = n + 3

C. n = 2

while n <= 8:

n = n + 3

print(n)

D. n = 2

while n >= 8:

print(n)

n = n + 3

8 Which of the following best describes what the functioncomputereturns?

def compute(values):

result = 0

for value in values:

result = result + value

return result

A It returns the largest value in the listvalues

B It returns the number of elements in the listvalues

C It returns the smallest value in the listvalues

D It returns the sum of all the elements in the listvalues

9 Which of the following best describes what the functioncomputereturns?

def compute(n):

i = n

sum = 0

while i <= 10:

sum = sum + i

i = i + 1

return sum

A. It returns the sum of integers fromn+1to10

B. It returns the sum of integers fromn+1to9

C. It returns the sum of integers fromnto9

D. It returns the sum of integers fromnto10

10 What would be output by the following statements?

n = 5

while n >= 2:

print(n + 1)

n = n - 3

Question 10 options:

A. 6

3

B. 3

C. 5

4

D. 6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions