I created a python program to calculate e and it used to last till sometime, but now suddenly it It's no longer dealing with more work and weird behavior here is the source code:
import from decimal import * time of import = int (input (Enter 'number of digits:') ) Getcontext () Prec = dig +5 def factorial (n): number = decimal (1) while decimal (n) & gt; = Decimal (1): number = decimal (number) * decimal (n) n = decimal (n) - decimal (1) return decimal (num) def calce (n): def calso (n): for i = 0 In the range (0, N + 1): E = E + decimal ((decimal (2) * decimal (i) + decimal (2)) / decimal (factorial (decimal) (decimal) (2) * decimal (i) +1)) decimal (e) n = int (how many frequencies for 'e':?)) T = time.clock () numb = str (calce) (n)) numb = numb [: - 4 ] F = open ("edigits.txt", 'w') f.write (str (dig)) f.write ("numeral.") F.write ("N") f.write (str (n)) F.write ("! \ N \ n") f.write (numb) t = str (time.clock () - t0) f.seek (0, 0) F.write (t) f.write ("seconds . \ N \ N ") f.close ()
This works even when I do not write it in the file, but when I do this it only passes the time and nothing else And some may still give this random number as well, but this is ... any help?
The problem is (0, N + 1) in E: E = E + decimal ((decimal ( 2)): * decimal (i) + decimal (2)) / decimal (factorial (decimal (2) * decimal (i) +1)) return decimals (e) < P> Your Calce
function also defines a local function, whose name is also calce
, does nothing with it, and does nothing, and Just falls from the end, back to none
. Therefore, when you run your program, then numbness
is always the string 'none'
and nothing else happens.
If you fix this, then by removing the extra def
line, or local function (such as return calls (n)
after local definition) By calling on, you get the appropriate results (e.g., 2.71828
when given as 5
and 10
), I'm pretty sure That's it's your problem.
However, code> F.sec (0, 0) means that you overwrite the beginning of your output with time information, which you almost certainly do not want Were.
Comments
Post a Comment