Quiz07-Iteration/Looping

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

What is displayed by the following code?
for i in range(3):
print ("Go ")
for j in range(3):
print ("Huskies! ")

Go
Huskies!
Huskies!
Huskies!
Go
Huskies!
Huskies!
Huskies!
Go
Huskies!
Huskies!
Huskies!

2
New cards

What is displayed by the following code?
for i in range(3):
print ("Go ")
for j in range(i + 1):
print ("Huskies! ")

Go
Huskies!
Go
Huskies!
Huskies!
Go
Huskies!
Huskies!
Huskies!

3
New cards

Which of the following are true?
1.You can nest if statements within loops
2.You can nest loops within if statements
3.You cannot nest loops within other loops

1 and 2

4
New cards

What is displayed by the following code?
word = "milkshake"
print (word[3])

k

5
New cards

Which of the following for loops designs will repeat 10 times?
1.for x in range(10):
2.for y in range(1, 10):
3.for z in range(1, 11):

1 and 3

6
New cards

Given the following code, what is stored in q?
def mangle(x, y):
if x > y:
z = 8
else:
z = 6
return z
def tangle (c):
b = 0
j = 1
while j < c:
b += j
j *= 2
return b
q = tangle(mangle(30, 60))

7

7
New cards

Look up the random object (Links to an external site.) in the Python online documentation
Which of the following functions of the random object returns a random floating point number in the range of 0.0 up to 1.0 (but not including 1.0)?

Random

8
New cards

What is the term for a special value that indicates that a repetitive process should stop?

exit sentinel

9
New cards

How many times will Hello be displayed in the code below?
def showStuff():
for j in range(3):
print ("Hello")
for i in range(4):
showStuff()

12 (with margin: 0)

10
New cards

How many times will "Hello" be displayed in the program below?
def showStuff( k ):
for i in range(k):
print ("Hello")
for j in range(3):
showStuff( j )

3 (with margin: 0)

11
New cards

A loop cannot contain a selection structure in its body.

False

12
New cards

A loop can be placed in any branch of a selection structure.

True

13
New cards

What will be displayed by the program code below?
a = 4
b = 2
if a > 3 and a < 7:
if( b != 2 ):
print (a + b)
else:
print (a - b)
else:
print (b - a)

2 (with margin: 0)

14
New cards

What string is stored in the variable result after this code executes? Remember to write your answer using quotes.
result = '' # starts as the empty stringfor ch in 'shoes':
result = ch + result

"seohs"

15
New cards

Which method returns true if a string contains only alphabetical letters?

isalpha()