Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

while loop countdown python

import time

i = 4
while i > 1:
    i -= 1
    # delay of 1 second.
    time.sleep(1)
    print(i)
# output will be 3, (delay of 1 sec) 2, (delay of 1 sec) 1
Comment

while loop countdown python

# import the time module
import time
  
# define the countdown func.
def countdown(t):
    
    while t:
        mins, secs = divmod(t, 60)
        timer = '{:02d}:{:02d}'.format(mins, secs)
        print(timer, end="
")
        time.sleep(1)
        t -= 1
      
    print('Fire in the hole!!')
  
  
# input time in seconds
t = input("Enter the time in seconds: ")
  
# function call
countdown(int(t))
Comment

PREVIOUS NEXT
Code Example
Python :: python read music stream 
Python :: how to add 2 dates in python 
Python :: matplotlib transparent line 
Python :: python nmap 
Python :: command prompt pause in python 
Python :: show a image in python 
Python :: dot product python 
Python :: ImportError: No module named pip --Windows 
Python :: Get Key From value in dictionary 
Python :: py insert char at index 
Python :: how to sort a column with mixed text number 
Python :: q django 
Python :: sklearn rmse 
Python :: or statement django template 
Python :: pandas string does not contain 
Python :: python lowercase 
Python :: numpy print options 
Python :: savefig resolution 
Python :: log of number python 
Python :: timed loop python 
Python :: from django.conf.urls import patterns 
Python :: timestamp in python 
Python :: nlargest hierarchy series pandas 
Python :: python control browse mouse selenium 
Python :: print python 
Python :: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied. 
Python :: django filter text first character upper case 
Python :: mount drive google colab 
Python :: remove spaces from input python 
Python :: how to invert a list in python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =