Advertisement
mengyuxin

calc_prod.py

Jan 6th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. #! python3
  2. # calc_prod.py
  3.  
  4. import time
  5.  
  6. def calc_prod():
  7.     # Calculate the product of the first 100,000 numbers.
  8.     product = 1
  9.     for i in range(1, 100000):
  10.         product *= i
  11.     return product
  12.  
  13. start_time = time.time()
  14. prod = calc_prod()
  15. end_time = time.time()
  16.  
  17. print('The result is %s digits long.' % (len(str(prod))))
  18. print('Took %s seconds to calculate.' % (end_time - start_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement