Loops Test
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
20 Questions
5 points
5
Question 1
1.
What is output by the code below?w = 20while w < 60: w += w // 2print(w)
What is output by the code below?
w = 20
while w < 60:
w += w // 2
print(w)
5 points
5
Question 2
2.
What is output by the code below?r = 1while( r < 50 ): r *= 3print(r)
What is output by the code below?
r = 1
while( r < 50 ):
r *= 3
print(r)
5 points
5
Question 3
3.
What is output by the code below?word = "the paintings"cnt = 0for letter in word: cnt += 1print(cnt)
What is output by the code below?
word = "the paintings"
cnt = 0
for letter in word:
cnt += 1
print(cnt)
5 points
5
Question 4
4.
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(3):
print("Hi", end = " " )
5 points
5
Question 5
5.
What is output by the code below?for x in range(10): print(x, end = " " )
What is output by the code below?
for x in range(10):
print(x, end = " " )
5 points
5
Question 6
6.
What is output by the code below?m = 5while( m > 0 ): m -= 3 print("dog")
What is output by the code below?
m = 5
while( m > 0 ):
m -= 3
print("dog")
5 points
5
Question 7
7.
What is output by the code below?j = 0while( j < 6 ): j += 4print(j)
What is output by the code below?
j = 0
while( j < 6 ):
j += 4
print(j)
5 points
5
Question 8
8.
What is output by the code below?for i in range (5): print(i, end = " " )
What is output by the code below?
for i in range (5):
print(i, end = " " )
5 points
5
Question 9
9.
What is output by the code below?num = 50while num > 0: if num > 20: num -= 10 else: num -= 15 print(num, end = " " )
What is output by the code below?
num = 50
while num > 0:
if num > 20:
num -= 10
else:
num -= 15
print(num, end = " " )
5 points
5
Question 10
10.
What is output by the code below?for x in range 2: print("light", end = " " )
What is output by the code below?
for x in range 2:
print("light", end = " " )
5 points
5
Question 11
11.
What is output by the code below?i = 4cnt = 0while i < 80: i *= iprint(cnt)
What is output by the code below?
i = 4
cnt = 0
while i < 80:
i *= i
print(cnt)
5 points
5
Question 12
12.
What is output by the code below?words = "math and science"i = 0for let in words: if let == "n": print(let) break i += 1
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
5 points
5
Question 13
13.
Which of the following would correctly fill /* code */ in method cntEs()?#method cntEs should return the count of all e’s in wordsdef cntOdds(words):cnt = 0 /* code */return cnt
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
5 points
5
Question 14
14.
What is output by the code below?sum = 0for t in range(2, 6): sum += tprint(sum)
What is output by the code below?
sum = 0
for t in range(2, 6):
sum += t
print(sum)
5 points
5
Question 15
15.
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 num in range(8, 12):
if num // 10 == 1:
print(num, end = " " )
5 points
5
Question 16
16.
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(4):
for j in range(3):
print(i + j, end = " " )
5 points
5
Question 17
17.
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?
for i in range(2,5):
for j in range(3, 6):
print(j, end = " " )
5 points
5
Question 18
18.
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?
word = "superhero"
for let in word:
if let != "h":
print(let, end = " " )
else:
break
5 points
5
Question 19
19.
What is output by the code below?j = 2word = "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?
j = 2
word = "music notes"
for let in word:
if j % 2 == 0:
print(let, end = " " )
else:
print(j, end = " " )
j = j + 1
5 points
5
Question 20
20.
What is output by the code below?s = 0while s = 10: s = s + 4print(s)
What is output by the code below?
s = 0
while s = 10:
s = s + 4
print(s)