COUNTDOWN TIMER Using Python.

0




COUNTDOWN TIMER Program using Python.

Follow the Following steps in your Preferred Code Editor:

Step 1:Import "time" Module ,using 'Import' Function.

Step 2:Take input from user using 'input' Function,

  and Typecast it into "integer" Data type using 'int'.

Step 3:Intialize a Variable 'i' so that we can create

  a range to print time in the timer.

Step 4:"for i in range(n,0,-1)" This part specifies initialization of the range

  from 'n' i.e User input to '0',by usng (-1) we specify that the

  countdown will run in a Reverse manner.

Step 5:"second=i%60

        minute=int(i/60)%60

        hour=int(i/3600)"

   This part Gets us the calculation part for our timer,

   Here we have used '%' operator which would return us the remainder after every iteration.

Step 6:"time.sleep(1)

        print(f"{hour:02}:{minute:02}:{second:02}")"

   In this part "time.sleep()" is used to make program rest for 1 second after

   Every iteration in the range.

   and in print statement we have used 'f' string so that we can use variables easily.

   Also "{hour:02}" values after ':' are format specifiers that are used to print '2' Zeros

   before our variable to look like as a Timer.

Step 7:Copy andd Paste the code And Don't Forget to Visit our Blog Again.


Short Description :

  • This code is a Python script that counts down from a time entered in seconds
  • The script uses a for loop to iterate through the countdown
  • The "time.sleep(1)" function is used to pause the script for one second before displaying the next countdown value
  • The "f" before the string in the print statement is used to format the output, ensuring that the hour, minute, and second values are always displayed with two digits
  • The final "print("Times Up!")" will be printed when the loop ends and the countdown reaches 0
  • The code can be useful for creating a timer or countdown feature on a website or application.
  • "Countdown to the finish line with this Python script! Enter any time in seconds and watch as the code ticks down the minutes and seconds until your deadline. The script uses a for loop and the "time.sleep(1)" function to create a seamless countdown experience. Say goodbye to clunky timers and hello to a polished and professional countdown feature on your website or application. Make sure your timer is always accurate by formatting the output to display hour, minute, and second values with two digits. Get ready to reach your goals with this user-friendly countdown script. "

CODE :


import time
n=int(input("Enter the Time in Seconds :"))
i=0
for i in range(n,0,-1):
  second=i%60
  minute=int(i/60)%60
  hour=int(i/3600)
  time.sleep(1)
  print(f"{hour:02}:{minute:02}:{second:02}")
print("Times Up!")




OUTPUT:



Tags

Post a Comment

0Comments
Post a Comment (0)