Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Imperfect Stopwatch
#1
Hey, I'm new here so if I break any rules, feel free to scold me.

Anyway, I was learning how to program a simple timer from a YouTube video. I got everything to work, and tweaked a few things myself. But when I compared it with an independent timer (phone and computer timer), I noticed that it runs a bit slower. By the two minute mark it's about 15 seconds behind the independent timer. Is there a way to improve this or would I have to completely start from scratch to get a more accurate one?

Oh, and I'm running 3.7.

Here's the code:

import time
from os import system

seconds = int(0)
minutes = int(0)
hours = int(0)

run = input("Enter R to run the program\n")

while run.lower()=="r":
    seconds = (seconds + 1)
    if seconds > 59:
        seconds = 0
        minutes += 1
    
    if minutes > 59:
        minutes = 0
        hours += 1
    system('cls')
    print(hours,":", minutes,":",seconds)
    time.sleep(1)
Reply


Messages In This Thread
Imperfect Stopwatch - by PoetLearnsPython - Jul-20-2019, 04:30 PM
RE: Imperfect Stopwatch - by ichabod801 - Jul-20-2019, 05:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error when trying to run a stopwatch nath2125 1 1,926 Feb-23-2019, 09:14 PM
Last Post: Yoriz
  stopwatch output to txt file robertofreemano 6 3,882 Jul-18-2018, 07:59 AM
Last Post: robertofreemano
  Stopwatch Panda 1 2,218 Jul-11-2018, 10:21 PM
Last Post: micseydel
  Stopwatch in Python/IPython shell suvadip 3 4,316 Jul-06-2018, 01:51 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020