Skip to content

Commit 799b58c

Browse files
committed
Day 5
1 parent d37cb5c commit 799b58c

13 files changed

+1066
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

Control Flow.ipynb

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"when all else fails use else(if required)\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"#if-elseif-else\n",
18+
"if 1>2:\n",
19+
" print \"if only one were greater tha 2\"\n",
20+
"elif 1>3:\n",
21+
" print \"elif stands for 'else if'\"\n",
22+
"else:\n",
23+
" print \"when all else fails use else(if required)\""
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 4,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": [
34+
"'odd'"
35+
]
36+
},
37+
"execution_count": 4,
38+
"metadata": {},
39+
"output_type": "execute_result"
40+
}
41+
],
42+
"source": [
43+
"#ternary if-then-else\n",
44+
"x=5\n",
45+
"parity = \"even\" if x%2==0 else \"odd\"\n",
46+
"parity"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": 5,
52+
"metadata": {},
53+
"outputs": [
54+
{
55+
"name": "stdout",
56+
"output_type": "stream",
57+
"text": [
58+
"0 is less than 10\n",
59+
"1 is less than 10\n",
60+
"2 is less than 10\n",
61+
"3 is less than 10\n",
62+
"4 is less than 10\n",
63+
"5 is less than 10\n",
64+
"6 is less than 10\n",
65+
"7 is less than 10\n",
66+
"8 is less than 10\n",
67+
"9 is less than 10\n"
68+
]
69+
}
70+
],
71+
"source": [
72+
"#while loop\n",
73+
"x=0\n",
74+
"while x<10:\n",
75+
" print x, \"is less than 10\"\n",
76+
" x=x+1"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 8,
82+
"metadata": {},
83+
"outputs": [
84+
{
85+
"name": "stdout",
86+
"output_type": "stream",
87+
"text": [
88+
"0 is less than 10\n",
89+
"1 is less than 10\n",
90+
"2 is less than 10\n",
91+
"3 is less than 10\n",
92+
"4 is less than 10\n",
93+
"5 is less than 10\n",
94+
"6 is less than 10\n",
95+
"7 is less than 10\n",
96+
"8 is less than 10\n",
97+
"9 is less than 10\n"
98+
]
99+
}
100+
],
101+
"source": [
102+
"#for and in\n",
103+
"for x in range(10):\n",
104+
" print x, \"is less than 10\""
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": 10,
110+
"metadata": {},
111+
"outputs": [
112+
{
113+
"name": "stdout",
114+
"output_type": "stream",
115+
"text": [
116+
"0\n",
117+
"1\n",
118+
"2\n",
119+
"4\n"
120+
]
121+
}
122+
],
123+
"source": [
124+
"for x in range(10):\n",
125+
" if x==3:\n",
126+
" continue\n",
127+
" if x==5:\n",
128+
" break\n",
129+
" print x\n",
130+
" "
131+
]
132+
}
133+
],
134+
"metadata": {
135+
"kernelspec": {
136+
"display_name": "Python 2",
137+
"language": "python",
138+
"name": "python2"
139+
},
140+
"language_info": {
141+
"codemirror_mode": {
142+
"name": "ipython",
143+
"version": 2
144+
},
145+
"file_extension": ".py",
146+
"mimetype": "text/x-python",
147+
"name": "python",
148+
"nbconvert_exporter": "python",
149+
"pygments_lexer": "ipython2",
150+
"version": "2.7.18"
151+
}
152+
},
153+
"nbformat": 4,
154+
"nbformat_minor": 2
155+
}

Generators and Iterators.ipynb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"def lazy_range(n):\n",
10+
" \"\"\"A lazy version of range\"\"\"\n",
11+
" i=0\n",
12+
" while i<n:\n",
13+
" yield i\n",
14+
" i+=1"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 2,
20+
"metadata": {},
21+
"outputs": [
22+
{
23+
"name": "stdout",
24+
"output_type": "stream",
25+
"text": [
26+
"0\n",
27+
"1\n",
28+
"2\n",
29+
"3\n",
30+
"4\n",
31+
"5\n",
32+
"6\n",
33+
"7\n",
34+
"8\n",
35+
"9\n"
36+
]
37+
}
38+
],
39+
"source": [
40+
"for i in lazy_range(10):\n",
41+
" print i"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": 5,
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"data": {
51+
"text/plain": [
52+
"[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]"
53+
]
54+
},
55+
"execution_count": 5,
56+
"metadata": {},
57+
"output_type": "execute_result"
58+
}
59+
],
60+
"source": [
61+
"lazy_evens_below_20 = [i for i in lazy_range(20) if i%2 == 0]\n",
62+
"lazy_evens_below_20"
63+
]
64+
}
65+
],
66+
"metadata": {
67+
"kernelspec": {
68+
"display_name": "Python 2",
69+
"language": "python",
70+
"name": "python2"
71+
},
72+
"language_info": {
73+
"codemirror_mode": {
74+
"name": "ipython",
75+
"version": 2
76+
},
77+
"file_extension": ".py",
78+
"mimetype": "text/x-python",
79+
"name": "python",
80+
"nbconvert_exporter": "python",
81+
"pygments_lexer": "ipython2",
82+
"version": "2.7.18"
83+
}
84+
},
85+
"nbformat": 4,
86+
"nbformat_minor": 2
87+
}

0 commit comments

Comments
 (0)