![]() ![]() PS: The program with wait for 1 second before printing the line “i second remaining.” #we also need the loop to wait for 1 second between each iteration Print(str(seconds-i) " seconds remaining \n") #Let's use a ranged loop to create the counter Seconds = int(input("How many seconds to wait")) #Asking user the duration for which the user wants to delay the process #this will enable to utilize specified functions within time library such as sleep() Let’s make a countdown timer function in Python Let’s try to understand the same with the help of an example: Example #1 After Python 3.5, the sleep() function provides a delay of at least the specified duration even if it’s being interrupted by a signal. The delay duration can be more than that specified due to any other activity scheduled in the system. The “duration” can be a more precise floating number as well instead of an integer. The “duration” for which we want to delay the execution is passed as an argument to the sleep() function in seconds. ![]() Python’s time library contains a predefined sleep() function, which can be called using the below Syntax: time.sleep(duration) In Short, Aliasing the Python library gives us the capability of utilizing this shorthand notation to call the time class as: t.function_name() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |