Python Countdown Challenge

Python Coding Exercise

 

This Python countdown challenge is a great Python coding exercise for beginners to practice loops along with functions. Your task is to write a Python 3 function that counts down from any given number to zero. The program should prompt the user to enter the starting number for the countdown and meet the following requirements:

  • Ask the user to enter the starting number for the countdown.
  • The countdown should include the starting number and reach zero.
  • The countdown should be displayed in descending order.
  • The countdown must pause for 1 second between each number.
  • The function should be able to handle any positive integer as the starting number.

Guide

To complete this Python assignment follow these steps:

  1. Import the time module to use the time.sleep(x) function.
  2. Define a function countdown that takes the starting number as input.
  3. Inside the function, use a while loop to iterate from the starting number down to 0.
  4. Inside the while loop, print the current number and then use time.sleep(1) to pause for 1 second.
  5. Decrement the current number in each iteration of the loop until it reaches 0.
  6. Prompt the user to input the starting number for the countdown.
  7. Call the countdown function with the user-input starting number.

Expected Output


Enter the starting number for the countdown: 10
10
9
8
7
6
5
4
3
2
1
0

For more Python exercises and challenges , visit our store.

Source code


import time

def countdown(start):
    while start >= 0:
        print(start)
        time.sleep(1)
        start -= 1

start_number = int(input("Enter the starting number for the countdown: "))
countdown(start_number)

 

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for practice
Register New Account
Shopping cart