Python Forum
Eulers Number Exercise
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Eulers Number Exercise
#1
Hi everbody, I'm really struggling with this excercise. Can somebody help me?

e (Eulers number) = 1/0! + 1/1! + 1/2! + 1/3! + 1/4! ⋯ + 1/n!

Try to get our own e . You need to write a function "factorial" to calculate the factorial number given the n and then use "for loop" to generate the e . Let n go from 0 to 10, and save the derived value of e in a list and print it out when n is an odd number (up to 10).

Hints: Consider use range(#begin, #end) method
Reply
#2
What have you tried?
Reply
#3
Thank you for your answer :-)

I just started learning python...

I tried:

def factorial:
n = (1/math.factorial(i))
 if i%2 != 0:
    print(numbers+(1/math.factorial(i))
and


numbers = [x for x in range(11)]
if i in numbers:
    if i%2 != 0:
    print(numbers+(1/math.factorial(i))
Reply
#4
You've got some good ideas, what I suggest:
Set e to zero
Create a for loop with a range of 11
In that loop, calculate 1/n!, add it to your e
Check to see if n is odd - if so, print your current value of e

When in doubt, write out in plain english what you believe the steps to be. Then code those steps. Google is your friend if you don't know how to code a particular step, or post here. We will help with a step, but obviously won't do the whole things for you
Reply
#5
You're also told to write your own function for computing the factorial, instead of using a library one..
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020