1import time, os
2
3seconds_to_go_for = 10 # How long the timer will go for
4current_time = int(time.time()) # Gets the time before the timer starts
5
6def clear():
7 if os.name == "nt":
8 os.system("cls") # Clear function, to avoid spam. Source: geeksforgeeks.org
9 else:
10 os.system("clear")
11
12while True:
13 time_now = int(time.time()) # Gets time during the timer's running
14 if time_now >= current_time + seconds_to_go_for: # Checks if enough time has passed
15 break # Stops loop if so
16
17 print(f"Seconds passed: {time_now - current_time}") # Prints how much time has passed
18 clear()
19print("The timer has ended")
1def hello():
2 print "hello, world"
3
4t = Timer(30.0, hello)
5t.start() # after 30 seconds, "hello, world" will be printed
6
1import time
2import os
3
4a = int(0)
5b = int(0)
6
7while True:
8 print(str(b) + " minutes " + str(a) + " seconds")
9 a += 1
10 time.sleep(0.9999999)
11 if a == 59:
12 a = 0
13 b += 1
14 os.system('cls')