Time Delay and Timers

Here’s an example with time delays:

import time

print(‘Hello’)
time.sleep(2)
print(‘How are you?’)

You only need to import time once.
The time.sleep() function waits for a specified number of seconds.

Here’s an example showing how to time how long it takes a user to answer a question:

import time
# store the system time before the question
t1 = time.time()

a = input('What is the capital of Iowa?')

# store the system time after the user input
t2 = time.time()

# Calculate the difference between the two times.
dt = t2 - t1

print("You took this many seconds to answer:")
print(dt)