@@ -55,16 +55,16 @@ print back onto the page. For example, we can compute π.
55
55
</head >
56
56
<body >
57
57
<py-script >
58
- print("Let's compute π:")
59
- def compute_pi(n):
60
- pi = 2
61
- for i in range(1,n):
62
- pi *= 4 * i ** 2 / (4 * i ** 2 - 1)
63
- return pi
64
-
65
- pi = compute_pi(100000)
66
- s = f"π is approximately {pi:.3f}"
67
- print(s)
58
+ print("Let's compute π:")
59
+ def compute_pi(n):
60
+ pi = 2
61
+ for i in range(1,n):
62
+ pi *= 4 * i ** 2 / (4 * i ** 2 - 1)
63
+ return pi
64
+
65
+ pi = compute_pi(100000)
66
+ s = f"π is approximately {pi:.3f}"
67
+ print(s)
68
68
</py-script >
69
69
</body >
70
70
</html >
@@ -93,17 +93,17 @@ the `<py-script>` tag to write to.
93
93
<br >
94
94
<div id =" pi" class =" alert alert-primary" ></div >
95
95
<py-script >
96
- import datetime as dt
97
- pyscript.write('today', dt.date.today().strftime('%A %B %d, %Y'))
96
+ import datetime as dt
97
+ pyscript.write('today', dt.date.today().strftime('%A %B %d, %Y'))
98
98
99
- def compute_pi(n):
100
- pi = 2
101
- for i in range(1,n):
102
- pi *= 4 * i ** 2 / (4 * i ** 2 - 1)
103
- return pi
99
+ def compute_pi(n):
100
+ pi = 2
101
+ for i in range(1,n):
102
+ pi *= 4 * i ** 2 / (4 * i ** 2 - 1)
103
+ return pi
104
104
105
- pi = compute_pi(100000)
106
- pyscript.write('pi', f'π is approximately {pi:.3f}')
105
+ pi = compute_pi(100000)
106
+ pyscript.write('pi', f'π is approximately {pi:.3f}')
107
107
</py-script >
108
108
</body >
109
109
</html >
@@ -144,15 +144,15 @@ as a shortcut, which takes the expression on the last line of the script and run
144
144
<h1 >Let's plot random numbers</h1 >
145
145
<div id =" plot" ></div >
146
146
<py-script output =" plot" >
147
- import matplotlib.pyplot as plt
148
- import numpy as np
147
+ import matplotlib.pyplot as plt
148
+ import numpy as np
149
149
150
- x = np.random.randn(1000)
151
- y = np.random.randn(1000)
150
+ x = np.random.randn(1000)
151
+ y = np.random.randn(1000)
152
152
153
- fig, ax = plt.subplots()
154
- ax.scatter(x, y)
155
- fig
153
+ fig, ax = plt.subplots()
154
+ ax.scatter(x, y)
155
+ fig
156
156
</py-script >
157
157
</body >
158
158
</html >
@@ -187,22 +187,22 @@ In the HTML tag `<py-env>`, paths to local modules are provided in the
187
187
- numpy
188
188
- matplotlib
189
189
- paths:
190
- - /data.py
190
+ - . /data.py
191
191
</py-env >
192
192
</head >
193
193
194
194
<body >
195
195
<h1 >Let's plot random numbers</h1 >
196
196
<div id =" plot" ></div >
197
197
<py-script output =" plot" >
198
- import matplotlib.pyplot as plt
199
- from data import make_x_and_y
198
+ import matplotlib.pyplot as plt
199
+ from data import make_x_and_y
200
200
201
- x, y = make_x_and_y(n=1000)
201
+ x, y = make_x_and_y(n=1000)
202
202
203
- fig, ax = plt.subplots()
204
- ax.scatter(x, y)
205
- fig
203
+ fig, ax = plt.subplots()
204
+ ax.scatter(x, y)
205
+ fig
206
206
</py-script >
207
207
</body >
208
208
</html >
0 commit comments