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:
- We should
print()
the value of thecountdown
variable. - We should decrease the value of the
countdown
variable by1
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