fork download
  1. import itertools
  2. from fractions import Fraction
  3.  
  4. def series(u0=Fraction(3, 2), u1=Fraction(5, 3)):
  5. yield u0
  6. yield u1
  7. while u0 != u1:
  8. un = 2003 - 6002/u1 + 4000/(u1*u0)
  9. yield un
  10. u1, u0 = un, u1
  11.  
  12. for i, u in enumerate(itertools.islice(series(), 100)):
  13. err = (2-u)/2 # relative error
  14. print("%d\t%.2g" % (i, err))
  15.  
Success #stdin #stdout 0.04s 6760KB
stdin
Standard input is empty
stdout
0	0.25
1	0.17
2	0.1
3	0.056
4	0.029
5	0.015
6	0.0077
7	0.0039
8	0.0019
9	0.00097
10	0.00049
11	0.00024
12	0.00012
13	6.1e-05
14	3.1e-05
15	1.5e-05
16	7.6e-06
17	3.8e-06
18	1.9e-06
19	9.5e-07
20	4.8e-07
21	2.4e-07
22	1.2e-07
23	6e-08
24	3e-08
25	1.5e-08
26	7.5e-09
27	3.7e-09
28	1.9e-09
29	9.3e-10
30	4.7e-10
31	2.3e-10
32	1.2e-10
33	5.8e-11
34	2.9e-11
35	1.5e-11
36	7.3e-12
37	3.6e-12
38	1.8e-12
39	9.1e-13
40	4.5e-13
41	2.3e-13
42	1.1e-13
43	5.7e-14
44	2.8e-14
45	1.4e-14
46	7.1e-15
47	3.6e-15
48	1.8e-15
49	8.9e-16
50	4.4e-16
51	2.2e-16
52	1.1e-16
53	5.6e-17
54	2.8e-17
55	1.4e-17
56	6.9e-18
57	3.5e-18
58	1.7e-18
59	8.7e-19
60	4.3e-19
61	2.2e-19
62	1.1e-19
63	5.4e-20
64	2.7e-20
65	1.4e-20
66	6.8e-21
67	3.4e-21
68	1.7e-21
69	8.5e-22
70	4.2e-22
71	2.1e-22
72	1.1e-22
73	5.3e-23
74	2.6e-23
75	1.3e-23
76	6.6e-24
77	3.3e-24
78	1.7e-24
79	8.3e-25
80	4.1e-25
81	2.1e-25
82	1e-25
83	5.2e-26
84	2.6e-26
85	1.3e-26
86	6.5e-27
87	3.2e-27
88	1.6e-27
89	8.1e-28
90	4e-28
91	2e-28
92	1e-28
93	5e-29
94	2.5e-29
95	1.3e-29
96	6.3e-30
97	3.2e-30
98	1.6e-30
99	7.9e-31