Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a) Write a generator function called gen_factorials(n) that generates the first

ID: 3827727 • Letter: A

Question

a) Write a generator function called gen_factorials(n) that generates the first n factorials, beginning with01 (which is 1 by definition), So, gen factorials(10) should generate this sequence: 0!, 1!, ... 9!, which is the same as 1, 1, 2, 6, 24, 120 720, 5040, 40320, 362880. Do NOT recompute the current factorial from scratch at each iteration. Instead preserve the current value between calls and update it. b) Write a Python expression using sum0 and a generator expression that computes an approximation e_star of Euler's number e = 2.718281..., the base of the natural logarithms, using the formula: e* = 1/0! + 1/1! + 1/2! + 1/3! + ..+ 1/n!, where n is a local positive int variable. Remember that the generator outputs the first n numbers from the factorial sequence. c) Use the functools.reduce(), map() functions, and lambda expressions to compute e_star, as defined for part b) To get credit do NOT use the sum() function. Assume n is a positive local int variable.

Explanation / Answer

[1]

def recur_factorial(n):
    for num in range(0,n):
        if num == 1:
        print("The factorial of",num,"is 1")
     else:
         count = 1
      for i in range(1,num):
        count = count*i
          print("The factorial of",num,"is",count)

[2]

import math

def e(n=10):

     return sum(1 / float(math.factorial(i)) for i in range(n))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote