105k views
2 votes
I need help converting this to python but i have no idea how to.

const tolerance := 0.0000001

function fac (x : real) : real
var answer : real := 1
if x = 0 or x = 1 then
result answer
else

for i : 1 .. round (x)
answer *= i
end for
result answer
end if
end fac

function e : real
var answer1 : real := 0
var answer2 : real := 1
var n : real := 0
loop
exit when abs (answer1 - answer2) <
tolerance
answer2 := answer1
answer1 += 1 / fac (n)
n += 1
end loop
result answer1
end e


put e

1 Answer

1 vote

Answer:

see below

Step-by-step explanation:

In Python, this code is much simpler.

It is a mathematical series to calculate e.

I need help converting this to python but i have no idea how to. const tolerance := 0.0000001 function-example-1
I need help converting this to python but i have no idea how to. const tolerance := 0.0000001 function-example-2
User Shauryachats
by
3.9k points