Loops Test

By Mickey Arnold
Last updated 10 months ago
20 Questions

What is output by the code below?
w = 20
while w < 60:
w += w // 2
print(w)

What is output by the code below?
r = 1
while( r < 50 ):
r *= 3
print(r)

What is output by the code below?
word = "the paintings"
cnt = 0
for letter in word:
cnt += 1
print(cnt)

What is output by the code below?
for x in range(3):
print("Hi", end = " " )

What is output by the code below?
for x in range(10):
print(x, end = " " )

What is output by the code below?
m = 5
while( m > 0 ):
m -= 3
print("dog")

What is output by the code below?
j = 0
while( j < 6 ):
j += 4
print(j)

What is output by the code below?
for i in range (5):
print(i, end = " " )

What is output by the code below?
num = 50
while num > 0:
if num > 20:
num -= 10
else:
num -= 15
print(num, end = " " )

What is output by the code below?
for x in range 2:
print("light", end = " " )

What is output by the code below?
i = 4
cnt = 0
while i < 80:
i *= i
print(cnt)

What is output by the code below?
words = "math and science"
i = 0
for let in words:
if let == "n":
print(let)
break
i += 1

Which of the following would correctly fill /* code */ in method cntEs()?
#method cntEs should return the count of all e’s in words
def cntOdds(words):
cnt = 0
/* code */
return cnt

What is output by the code below?
sum = 0
for t in range(2, 6):
sum += t
print(sum)

What is output by the code below?
for num in range(8, 12):
if num // 10 == 1:
print(num, end = " " )

What is output by the code below?
for i in range(4):
for j in range(3):
print(i + j, end = " " )

What is output by the code below?
for i in range(2,5):
for j in range(3, 6):
print(j, end = " " )

What is output by the code below?
word = "superhero"
for let in word:
if let != "h":
print(let, end = " " )
else:
break

What is output by the code below?
j = 2
word = "music notes"
for let in word:
if j % 2 == 0:
print(let, end = " " )
else:
print(j, end = " " )
j = j + 1

What is output by the code below?
s = 0
while s = 10:
s = s + 4
print(s)