Bye Bye clock. You are a programmer now you need to create your own clock. So here it is.
The code
import time
while True:
current_time = time.strftime("%I:%M:%S %p")
print(f"\t \t{current_time}")
time.sleep(1)
The result:
Explanation: This code imports the "time" library and then enters into an infinite loop. Inside the loop, the current time is retrieved in the format of "hours:minutes:seconds AM/PM" and then printed to the screen. The line "time.sleep(1)" makes the loop pause for one second before iterating again, so the current time is printed every second. As a result, this script will continue to run indefinitely and print the current time in the specified format every second.
No comments