Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 (10 points) Saved Which of the following while loops will not be an infinite loop? Question 1 options: i = 5 while i

Question 1 (10 points)

Saved

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

Question 1 options:

i = 5 while i >= 0: print(i) i = i - 1

i = 0 while i < 15: print(i) i = i - 1

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

i = 20 while i >= 10: print(i) i = i + 1

Question 2 (10 points)

Saved

What would be output by the following statements?

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

Question 2 options:

73

5

14.7

15

Question 3 (10 points)

Saved

Which of the following functions would return the number of positive elements in a list named numbers passed as a parameter?

Question 3 options:

def compute(numbers): count = 0 for number in numbers: if number > 0: count = count + 1 return count

def compute(numbers): count = 0 for number in numbers: count = count + 1 return count

def compute(numbers): count = 0 for number in numbers: count = count + number return count

def compute(numbers): count = None for number in numbers: if count is None or number < count: count = number return count

Question 4 (10 points)

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

Question 4 options:

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

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

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

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

Question 5 (10 points)

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)

Question 5 options:

13

5

79

1

Question 6 (10 points)

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

def compute(values): result = 0 for value in values: result = result + 1 return result

Question 6 options:

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

It returns the number of elements in the list values

It returns the largest value in the list values

It returns the smallest value in the list values

Question 7 (10 points)

What would be output by the following statements?

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

Question 7 options:

4 6 8

2 4 6

4 6

2 4

Question 8 (10 points)

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

Question 8 options:

n = 6 while n >= 0: print(n) n = n + 2

n = 6 while n > 0: print(n) n = n - 2

n = 6 while n >= 0: n = n + 2 print(n)

n = 6 while n >= 0: print(n) n = n - 2

Question 9 (10 points)

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

Question 9 options:

sum = 0 for value in [22, 4, 11, 3, 17]: sum = sum + 1 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 = value print('Sum:', sum)

Question 10 (10 points)

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 10 options:

It returns the sum of integers from n to 10

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

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

It returns the sum of integers from n to 9

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

ISBN: 133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago