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?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.