Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
Path: even numbers.ipynb
Views: 256Image: ubuntu2004
Kernel: Python 3 (system-wide)
Use a list comprehension to create a list containing all even numbers from 1 to 100 (including 100).
This first function uses a range from and then, using the mod operator evaluates each value to ensure it is an even number before printing that value.
This second function uses a range from and then, using an incrementation of in the , prints ever second value of
In [5]:
Out[5]:
Even numbers using mod (%):
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
Even numbers using increment of 2
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
In [0]: