Python Forum

Full Version: Understanding the concept ( Modules , imports )
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey fellas .
I've been trying to learn bunch of stuffs about modules and imports in Python , meanwhile I was stopped because of some codes in which I can't quite get the actual concept behind it's mechanism & how it works .
This is the code
import time
from time import time as my_timer
import random

input("Please enter to start")

wait_time = random.randint(1, 6)
time.sleep(wait_time)
start_time = my_timer()
input("Press enter to stop")

end_time = my_timer()

print("Started at " + time.strftime("%X", time.localtime(start_time)))
print("Ended at " + time.strftime("%X", time.localtime(end_time)))

print("Your reaction time was {} seconds".format(end_time - start_time))
I really appreciate if someone could just explain line by line of this code and what is really does for us . Cause I don't have any problems with running the code . I just want to comprehend the lines of code .
Thanks
You should use a timer that doesn't lock the process.
Sleep does this until complete.
Here's a timer class that I wrote some time ago, by looking at the code you should be able to get some ideas on how to write interruptible timer routines: https://python-forum.io/Thread-Multi-thr...imer-Class
Also, a good read is: https://pymotw.com/3/time/