Countdown With While Loop

Write a Python program that takes an integer input n from the user and prints all the numbers from n down to 0.

Example 1:

Input: n = 5 

Output: 5 4 3 2 1 0

Example 2:

Input: n = 2 

Output: 2 1 0

Use a while loop that continues as long as n is greater than or equal to 0.

n = int(input("Enter a number: "))
while n >= 0:
    print(n)
    n -= 1

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!