factorial.py 333 B

123456789
  1. def factorial():
  2. f, n = 1, 1
  3. while True: # First iteration:
  4. yield f # yield 1 to start with and then
  5. f, n = f * n, n+1 # f will now be 1, and n will be 2, ...
  6. for index, factorial_number in zip(range(51), factorial()):
  7. print('{i:3}!= {f:65}'.format(i=index, f=factorial_number))