ef calculate_e (n): *** Here use the variable e to denote and return the value of e. I have initiated the value of e (e=0) and defined the point where yo The value of variable n denotes the number of terms to use in the se So write the loop to compute the first n terms. "** e = 0. X = 1 # your code here (hản(onu nuthon
ef calculate_e (n): *** Here use the variable e to denote and return the value of e. I have initiated the value of e (e=0) and defined the point where yo The value of variable n denotes the number of terms to use in the se So write the loop to compute the first n terms. "** e = 0. X = 1 # your code here (hản(onu nuthon
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Need help on this question and can you explain how as well?
![def calculate_e(n):
Here use the variable e to denote and return the value of e.
I have initiated the value of e (e=0) and defined the point where you will evaluate the series - that is, at x=1.
The value of variable n denotes the number of terms to use in the series.
So write the loop to compute the first n terms.
e = 0.
X - 1
# your code here
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import math
def calculate(n):
e = 0
x = 1
for i in range (n):
# here we do not raising the x to power
# because x is 1 and 1 to the power any
# number is 1 but in case of change the
# x value
# uncomment this line and comment the below line
# e += (x**i/math.factorial (i))
e +=(x/math.factorial(i))
return e
calculate(16)
#Ln[3]
calculate(22)
#Ln[4]
calculate(44)
#Ln[5]
calculate(66)
2.7182818284590455](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F507f99da-9967-4c1f-a8fd-4e55d78bcba3%2Fc1932f45-45c3-4d64-88a4-8684d73eced6%2Fwpe1q15_processed.png&w=3840&q=75)
Transcribed Image Text:def calculate_e(n):
Here use the variable e to denote and return the value of e.
I have initiated the value of e (e=0) and defined the point where you will evaluate the series - that is, at x=1.
The value of variable n denotes the number of terms to use in the series.
So write the loop to compute the first n terms.
e = 0.
X - 1
# your code here
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import math
def calculate(n):
e = 0
x = 1
for i in range (n):
# here we do not raising the x to power
# because x is 1 and 1 to the power any
# number is 1 but in case of change the
# x value
# uncomment this line and comment the below line
# e += (x**i/math.factorial (i))
e +=(x/math.factorial(i))
return e
calculate(16)
#Ln[3]
calculate(22)
#Ln[4]
calculate(44)
#Ln[5]
calculate(66)
2.7182818284590455

Transcribed Image Text:Q4: complete the function that calculates the Euler's number e from the series you learnt during the maths lessons. The funcion takes in the value n, this will be the term that you truncate the series at. Also use the following hints.
Hint 1: remember the Maclaurin Expansion e* = 1+ x +
Hint 2: you will need to use a for loop,
Hint 3: e = e', when x=1 for e*
Hint 4: use the math.factorial(i) to caluclate factorial of i. THAT IS: i! = math.factorial(i)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education