2

I want to use a stopwatch to time my code, but I need help with it. This is my code:

import time
timer = 0
alreadyout = 'no'
eligable = 'no'
entered = 'no'
if alreadyout == 'no' and eligable == 'no':
  answer = str(input("type to 100 letters as fast as you can"))
  if len(answer) == 100:
    eliable = 'yes'
    entered = 'yes'
  alreadyout = 'yes'

while entered == 'no':
  time.sleep(1)
  timer = timer + 1
print(timer)
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

6

You can use time.time() to time your code. Here is an example

import time

start = time.time()
# <code to time>
end = time.time()

print(f"Time taken to run the code was {end-start} seconds")
Shubham
  • 1,310
  • 4
  • 13