In: Computer Science
Write a python program to create a list of integers using random function. Use map function to process the list on the series: x + x2/2! + x3/3! + ….n and store the mapped elements in another list. Assume the value of n as 10
PYTHON PROGRAM:
# import random function
import random
# fct() function for factorial
# return the factorial for given number n
def fct(n):
if n == 1:
return 1
else:
return n * fct(n - 1)
# process() function
# process the list on the series: x + x^2/2! + x^3/3! +.....n
def processfun(x):
series_total = x
# Assume the value of n as 10
# evaluate the series
# then return the series_total
for i in range(1,11):
series_total = series_total + (pow(x, i) / fct(i))
return series_total
# create a list of integers using random function
# between 1- 10
# Use map function to process the list on the series:
# store the mapped elements in another list.
x = random.sample(range(1, 10), 5)
mp = map(processfun, x)
# Now,Convert the map into a list,
# Display list
print(list(x))
print(list(mp))
CODE SCREENSHOT:
OUTPUT:
NOTE: If you don't understand any step please let me know at once.