Python Forum
Error when trying to run a stopwatch
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when trying to run a stopwatch
#1
Im getting an error when running this def and im not sure why. Its meant to be a stopwatch that runs and counts during what ever code you set it to start on.

def stopWatch(value):
    '''From seconds to Days;Hours:Minutes;Seconds'''

    valueD = (((value/365)/24)/60)
    Days = int (valueD)

    valueH = (valueD-Days)*365
    Hours = int(valueH)

    valueM = (valueH - Hours)*24
    Minutes = int(valueM)

    valueS = (valueM - Minutes)*60
    Seconds = int(valueS)

    print("and you finished in", Days "days", Hours "Hours", Minutes "Minutes", Seconds "Seconds")


start = time.time() # What in other posts is described is

input("test ")

end = time.time()         
stopWatch(end-start) #Use then my code
Reply
#2
You should state the error you are getting.
The time module is being used but has not been imported.
There are syntax errors in your print statement due to using a variable followed by a space followed by a string.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Imperfect Stopwatch PoetLearnsPython 1 1,531 Jul-20-2019, 05:58 PM
Last Post: ichabod801
  stopwatch output to txt file robertofreemano 6 3,820 Jul-18-2018, 07:59 AM
Last Post: robertofreemano
  Stopwatch Panda 1 2,177 Jul-11-2018, 10:21 PM
Last Post: micseydel
  Stopwatch in Python/IPython shell suvadip 3 4,208 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