Commit 83cd4f53 authored by Wenchao Zhang's avatar Wenchao Zhang ✍️
Browse files

renew test

parent 181447f2
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
%% Cell type:markdown id: tags:

## itertools

%% Cell type:code id: tags:

``` python
``` 
# 使用交错级数计算pi
import itertools
from functools import reduce
def pi(N):
    cc = itertools.cycle([4, -4])
    odds = itertools.count(1,2)
    ns = list(itertools.takewhile(lambda x: x <= 2*N-1, odds))
    pp = reduce(lambda x, y: x + y, map(lambda x: next(cc)/x, ns))
    return pp

pi(100)
```

%% Output

3.1315929035585537

%% Cell type:code id: tags:

``` python
``` 
import itertools

def pi(N):
    odd = itertools.count(1, 2)
    o = itertools.takewhile(lambda x: x < 2 * N, odd)
    c = itertools.cycle([4, -4])
    p = sum([next(c) / i for i in o])
    return p

pi(10)
```

%% Output

3.0418396189294032

%% Cell type:code id: tags:

``` python
``` 
100//25
```

%% Output

4

%% Cell type:code id: tags:

``` python
a=5
print(a+5)
```

%% Output

10

%% Cell type:code id: tags:

``` python
```