logo CodeStepByStep logo

while_loops

Language/Type: Python basics while loops

For each of the following while loops, how many times will the loop execute its body? Remember that "zero," "infinity," and "unknown" are legal answers.

# a.
x = 1
while x < 100:
    print(x, end=" ")
    x += 10
# b.
max = 10
while max < 10:
    print("count down:", max)
    max -= 1
# c.
x = 250
while x % 3 != 0: 
    print(x)
# d.
x = 2
while x < 200: 
    print(x, end=" ") 
    x *= x
# e.
word = "a"
while len(word) < 10:
    word = "b" + word + "b"
print(word)
# f.
x = 100
while x > 0: 
    print(x // 10) 
    x = x // 2
a.
b.
c.
d.
e.
f.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.