I am making small program(timer) with great and counting the last event but the time goes repeating | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I am making small program(timer) with great and counting the last event but the time goes repeating

import os import time s=0 m=0 while s<= 60 : os.system( 'cls' ) print (m, 'Minutes' , s, 'Second time.sleep( 1) s+= 1 if s== 60: m+= 1 s= 0

16th Dec 2017, 7:54 PM
Ahmed Mohamed Aden
5 Answers
+ 1
While there is technically nothing wrong with your method of implementation the accuracy may not be exactly what you are hoping for. time.sleep() is not 100% exact. Python will sleep and check to see if the defined amount of time has passed before continuing. At the beginning of the execution that will be fine but eventually all the extra milliseconds will compound to throw your timer off. I would recommend looking into a delta time function. With every loop check to see if the time is greater than the last time an update occurred.
16th Dec 2017, 8:04 PM
Kevin Gilkey-Graham
Kevin Gilkey-Graham - avatar
0
<!DOCTYPE html> <html> <head> <script> function startTime() { var today = new Date(); var h = today.getHours(); var m = today.getMinutes(); var s = today.getSeconds(); m = checkTime(m); s = checkTime(s); document.getElementById('txt').innerHTML = h + ":" + m + ":" + s; var t = setTimeout(startTime, 500); } function checkTime(i) { if (i < 010) {i = "0" + i}; return i;
20th Dec 2017, 8:04 AM
Ahmed Mohamed Aden
0
bro i was making clock but the clock was not appearing totally
20th Dec 2017, 8:05 AM
Ahmed Mohamed Aden
0
what is wrong bro with my code and what do you think i have to check on, I am using PC and chrome as browser
20th Dec 2017, 8:07 AM
Ahmed Mohamed Aden
0
what is wrong bro with my code and what do you think i have to check on, I am using PC and chrome as browser
20th Dec 2017, 8:07 AM
Ahmed Mohamed Aden