time()

  1. If you want to measure how long it takes a program to run, you may prepare your program in the following way:
    
    from time import time
    start_time = time()
    
    #	.
    #	.
    #	.
    # main program which does the work
    #	.
    #	.
    #	.
    
    end_time = time()
    print("It takes", end_time - start_time, "seconds to run the program.")
    
    
  2. The time() function returns the time in seconds since the epoch as a floating point number.
  3. Modify your previous exercise for multiplication, so that it will measure how long it takes you to finish the multiplication exercise.

The program may run as follows:

98 * 43 = 4314
Wrong! 98*43=4214
98 * 68 = 6664
17 * 28 = 476
73 * 69 = 5037
12 * 44 = 528
41 * 26 = 1066
69 * 9 = 621
97 * 20 = 1940
48 * 68 = 3264
56 * 90 = 5040
You made 1 mistake today.       You spent 40 seconds in this exercise.