Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 How many times does a loop with the header for count in xrange(10): execute th

ID: 3664753 • Letter: 1

Question

1 How many times does a loop with the header for count in

xrange(10): execute the statements in its body?

a 9 times

b 10 times

c 11 times

2 A for loop is convenient for

a making choices in a program

b running a set of statements a predictable number of times

c counting through a sequence of numbers

d describing conditional iteration

3 What is the output of the loop for count in xrange(5):

print count?

a 1 2 3 4 5

b 1 2 3 4

c 0 1 2 3 4

4 When the function xrange receives two arguments, what does the

second argument specify?

a the last value of a sequence of integers

b the last value of a sequence of integers plus 1

c the last value of a sequence of integers minus 1

5 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

b 5

6 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

7 By default the while loop is an

a entry-controlled loop

b exit-controlled loop

8 Consider the following code segment:

ƒƒƒcountƒ=ƒ5

ƒƒƒwhileƒcountƒ>ƒ1:

ƒƒƒƒƒƒprintƒcount,

ƒƒƒƒƒƒcountƒ-=ƒ1

What is the output produced by this code?

a 1 2 3 4 5

b 2 3 4 5

c 5 4 3 2 1

d 5 4 3 2

9 Consider the following code segment:

ƒƒƒcountƒ=ƒ1

ƒƒƒwhileƒcountƒ<=ƒ10:

ƒƒƒƒƒƒprintƒcount,

Which of the following describes the error in this code?

a The loop is off by 1.

b The loop control variable is not properly initialized.

c The comparison points the wrong way.

d The loop is infinite.

10 Consider the following code segment:

ƒƒƒsumƒ=ƒ0.0

ƒƒƒwhileƒtrue:

11 The expression len(data) evaluates to

a 8

b 7

c 6

12 The expression data[1] evaluates to

a 'N'

b 'o'

13 The expression data[-1] evaluates to

a '!'

b 'y'

14 The expression data[3:6] evaluates to

a 'way!'

b 'way'

c ' wa'

15 The expression data.replace(“No”, “Yes”) evaluates to

a 'No way!'

b 'Yo way!'

c 'Yes way!'

16 The expression data.find(“way!”) evaluates to

a 2

b 3

c True

17 A Caesar cipher locates the coded text of a plain text character

a A given distance to the left or the right in the sequence of characters

b In an inversion matrix

18 The binary number 111 represents the decimal integer

a 111

b 3

c 7

19 Which of the following binary numbers represents the decimal integer

value 8?

a 11111111

b 100

c 1000

20 Which file method is used to read the entire contents of a file in a

single operation?

a readline

b read

c a for loop

Explanation / Answer

1 How many times does a loop with the header for count in
xrange(10): execute the statements in its body?
Answer:
b 10 times

2 A for loop is convenient for
Answer:
b running a set of statements a predictable number of times

3 What is the output of the loop for count in xrange(5):
print count?
Answer:
c 0 1 2 3 4

4 When the function xrange receives two arguments, what does the
second argument specify?
Answer:
b the last value of a sequence of integers plus 1

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

6 A Boolean expression using the and operator returns True when
Answer:
a both operands are true

7 By default the while loop is an
Answer:
a entry-controlled loop

8 Consider the following code segment:
ƒƒƒcountƒ=ƒ5
ƒƒƒwhileƒcountƒ>ƒ1:
ƒƒƒƒƒƒprintƒcount,
ƒƒƒƒƒƒcountƒ-=ƒ1
What is the output produced by this code?
Answer:
c 5 4 3 2 1

19 Which of the following binary numbers represents the decimal integer
value 8?
Answer:
b 100

20 Which file method is used to read the entire contents of a file in a
single operation?

b read