Timer in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Timer in python

Asking help from all python experts. I'm busy with code in python where in one part I would like to add a timer. The user must input a time in minutes (say 5 min) and a percentage of a minute (say 25%). The timer output must then print for 15 seconds (25% of 1 minutes) start and then after 15 seconds print stop for 45 seconds. This must then loop for 5 minutes what the first user input was. Can anybody help me with the code for this?

14th Jul 2017, 1:50 PM
Gys Coetzee
Gys Coetzee - avatar
3 Answers
+ 8
at the start: import time when you want to time something: time.sleep(number of seconds)
14th Jul 2017, 9:57 PM
Cheesy Game Studios
Cheesy Game Studios - avatar
0
The 'time' module will help you: study this link, and try to code it yourself: and ask for more specific help when you have some code to correct/improve ^^ https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_date_time.htm
14th Jul 2017, 2:49 PM
visph
visph - avatar
0
Thanks Cheesy Game Studios for pushing me in the right direction. I've got the following code but the code won't stop at the set time the user entered. Any help please???? # input t = float(input("Enter time in minutes: ")) perc = float(input("Enter percentage of a minute: ")) # calculations sec = (t * 60) # calculating the time from minutes into seconds and how long the code must run until it stop perc_start = ((perc / 100) * 60) # how long the start message must show perc_stop = (60 - perc_start) # how long the stop message must show # output print("Total time in seconds = " + str(sec)) print("Total time in seconds that system must start per minute = " + str(perc_start)) print("Total time in seconds that system must stop per minute = " + str(perc_stop)) # pivot start stop import time t_total = 0 while t_total <= sec: print("Start") time.sleep(perc_start) print("Stop") time.sleep(perc_stop)
16th Jul 2017, 7:58 PM
Gys Coetzee
Gys Coetzee - avatar