How to create StopWatch with Python????
Hi Everyone, How are you all?
Here I came up with a good and easy project to create for beginners who are learning python and all other languages but only used for programming. Ok let's stop wasting time and get started.
- First of all we have to create a new project or new file in pycharm or visual studio code etc.... to write our code. The file should be in the (.py) format.
- Next step is to import time because it is important for a watch which Is stopwatch. Let's import it with this line of code: import time
- And Then let's import os this will give us the output in clear format. Here is the code: import os
- Next Declare variable for seconds, minutes and hours.
- At last write the code for the stopwatch to run In the while loop funtion and that's it we have created the stopwatch successfully in python.
Here is the full code for Stopwatch:
import os
import time
second = 0
minute = 0
hours = 0
print("Simple Stopwatch(in Python) Created By PyTechTip...")
while(True):
print('\n\n\n\n\n\n\n')
print('\t\t\t\t-------------')
print('\t\t\t\t %d : %d : %d '%(hours,minute,second))
print('\t\t\t\t-------------')
time.sleep(1)
second+=1
if(second == 60):
second = 0
minute+=1
if(minute == 60):
minute = 0
hour+=1;
os.system('cls')
Thank you for reading this amazing tutorial blog.
In soon A tutorial video will be ready to see all these letters in visuals.
Good bye. Stay Safe. Happy Programming.