Python - Chapter 3 Quiz

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How many times does a loop with the header for count in range (10): execute the statements in its body? a. 10 times b. 12 times c. 9 times d. 11 times

a. 10 times

Consider the following code segment: x = 5 y = 4 if x > y: print(y) else: print(x) What value does this code segment print?

a. 4

Consider the following code segment, which is intended to print the integers 1 through 10: count = 1 while count <= 10: print(count, end = " ") Which of the following describes the error in this code? a. The loop is infinite. b. The loop control variable is not properly initialized. c. The comparison points the wrong way. d. The loop is off by 1

a. The loop is infinite.

A Boolean expression using the and operator returns True when a. both operands are true b. one operand is true c. neither operand is true d. one operand is false

a. both operands are true

By default, the while loop is a(n) a. entry-controlled loop b. exit-controlled loop c. count-controlled loop d. loop that iterates a definite, preestablished number of times

a. entry-controlled loop

A for loop is convenient for a. running a set of statements a predictable number of times. b. counting through a sequence of numbers. c. making choices in a program. d. describing conditional iteration.

a. running a set of statements a predictable number of times. b. counting through a sequence of numbers.

What is the output of the loop for count in range(5): print(count, end = " ")? a. 0 1 2 3 4 5 b. 0 1 2 3 4 c. 1 2 3 4 d. 1 2 3 4 5

b. 0 1 2 3 4

Consider the following code segment: theSum = 0.0 while True: number = input("Enter a number: ") if number == "": break theSum += float(number) How many iterations does this loop perform? a. None b. At least one c. Zero or more d. Ten

b. At least one

Consider the following code segment: count = 5 while count > 1: print(count, end = " ") count -= 1 What is the output produced by this code? a. 5 4 3 2 1 b. 2 3 4 5 c. 5 4 3 2 d. 1 2 3 4 5

c. 5 4 3 2

When the function range receives two arguments, what does the second argument specify? a. The last value of a sequence of integers minus 1 b. The last value of a sequence of integers c. The last value of a sequence of integers plus 1 d. The step value for the loop

c. The last value of a sequence of integers plus 1


Kaugnay na mga set ng pag-aaral

Chapters 12, 7, 2, - Land and Water Use

View Set

Elements of Culture Greenleaf test

View Set

Membrane Proteins (Course Pack 9)

View Set