I can't get through this exercise

This exercise is this.

Now let’s tackle the actual while loop. Define a while loop that will run while our countdown variable is greater than or equal to zero.

On each iteration:

  1. We should print() the value of the countdown variable.
  2. We should decrease the value of the countdown variable by 1

Make sure to only print the value of countdown.

https://www.codecademy.com/courses/learn-python-3/lessons/learn-python-loops/exercises/while

and my solution, what mistake do I do?

# While Loop Walkthrough
count = 0
print("Starting While Loop")
while count <= 3:
  # Loop Body
  # Print if the condition is still true
  print(count)
  print("Loop Iteration - count <= 3 is still true")
  # Print the current value of count 
  print("Count is currently " + str(count));
  # Increment count
  count += 1
  print(" ----- ")
print("While Loop ended")

# Your code below: 

countdown = 10
while countdown >= 0:
  print(countdown)
countdown -= 1

It keeps crashing when I hit “run”. So I need always to refresh.
Thanks!

#python3

We cannot see your indentation; does your code look like this?

countdown = 10
while countdown >= 0:
    print(countdown)
    countdown -= 1

My code for this question 3 is:

countdown = 10
while countdown >= 0:
print(countdown)
countdown -= 1

https://www.codecademy.com/courses/learn-python-3/lessons/learn-python-loops/exercises/while

Unfortunately I still get error message “Did you remember to print countdown and decrease it by 1 on each iteration of the loop?”

Is your loop correctly indented? We cannot tell if that is a problem, or not.

Thank you for your quick reply.

Yes, I correctly indented it.

countdown = 10
while countdown >= 0:
print(countdown)

Loop Body

Print if the condition is still true

print(“Loop Iteration - countdown >= 0 is still true”)

print the current value of count

print(“Countdown is currently” + str(countdown))

Increment countdown

countdown -= 1
print(" ----- ")
print(“While Loop ended”)

Now if you could take a moment to browse the new user section for tips on how to post code samples in the forums, that would be cool.

1 Like