Skip to content

Commit 682bf59

Browse files
update loop files
1 parent abc8491 commit 682bf59

File tree

1 file changed

+208
-0
lines changed

1 file changed

+208
-0
lines changed

00 Examples/lecture09/loop.ipynb

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"id": "46d1a4f3",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"w\n",
14+
"e\n",
15+
"l\n",
16+
"c\n",
17+
"o\n",
18+
"m\n",
19+
"e\n"
20+
]
21+
}
22+
],
23+
"source": [
24+
"data = \"welcome\"\n",
25+
"# print(data)\n",
26+
"\n",
27+
"for i in data:\n",
28+
" print(i)"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 4,
34+
"id": "d78d42bb",
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"name": "stdout",
39+
"output_type": "stream",
40+
"text": [
41+
"0\n",
42+
"1\n",
43+
"2\n",
44+
"3\n",
45+
"4\n",
46+
"5\n",
47+
"6\n",
48+
"7\n",
49+
"8\n",
50+
"9\n"
51+
]
52+
}
53+
],
54+
"source": [
55+
" # range(endvalue) start 0\n",
56+
" \n",
57+
"for i in range(10):\n",
58+
" print(i)"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 5,
64+
"id": "51b2e9a2",
65+
"metadata": {},
66+
"outputs": [
67+
{
68+
"name": "stdout",
69+
"output_type": "stream",
70+
"text": [
71+
"10\n",
72+
"11\n",
73+
"12\n",
74+
"13\n",
75+
"14\n",
76+
"15\n",
77+
"16\n",
78+
"17\n",
79+
"18\n",
80+
"19\n"
81+
]
82+
}
83+
],
84+
"source": [
85+
"# range(startvalue,endvalue)\n",
86+
"for i in range(10,20):\n",
87+
" print(i)"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 7,
93+
"id": "c346d721",
94+
"metadata": {},
95+
"outputs": [
96+
{
97+
"name": "stdout",
98+
"output_type": "stream",
99+
"text": [
100+
"1\n",
101+
"4\n",
102+
"7\n",
103+
"10\n",
104+
"13\n",
105+
"16\n",
106+
"19\n"
107+
]
108+
}
109+
],
110+
"source": [
111+
"# range(startvalue,endvalue,step)\n",
112+
"for i in range(1,21,3):\n",
113+
" print(i)"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 11,
119+
"id": "52e27d7f",
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"name": "stdout",
124+
"output_type": "stream",
125+
"text": [
126+
"b\n",
127+
"86\n"
128+
]
129+
}
130+
],
131+
"source": [
132+
"# chr() number to ascii value\n",
133+
"\n",
134+
"x = 98\n",
135+
"print(chr(x))\n",
136+
"\n",
137+
"# ord() ascii value to number\n",
138+
"\n",
139+
"c = \"V\"\n",
140+
"print(ord(c))"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": 15,
146+
"id": "b281f7b8",
147+
"metadata": {},
148+
"outputs": [
149+
{
150+
"name": "stdout",
151+
"output_type": "stream",
152+
"text": [
153+
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
154+
]
155+
}
156+
],
157+
"source": [
158+
"for i in range(65,91):\n",
159+
" print(chr(i),end=\" \")"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": 18,
165+
"id": "ae1ec09b",
166+
"metadata": {},
167+
"outputs": [
168+
{
169+
"name": "stdout",
170+
"output_type": "stream",
171+
"text": [
172+
"45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|"
173+
]
174+
}
175+
],
176+
"source": [
177+
"# how to take user input \n",
178+
"\n",
179+
"start = int(input('enter start value ..'))\n",
180+
"end = int(input('enter end value..'))\n",
181+
"\n",
182+
"for i in range(start,end+1):\n",
183+
" print(i,end=\"|\")"
184+
]
185+
}
186+
],
187+
"metadata": {
188+
"kernelspec": {
189+
"display_name": "Python 3",
190+
"language": "python",
191+
"name": "python3"
192+
},
193+
"language_info": {
194+
"codemirror_mode": {
195+
"name": "ipython",
196+
"version": 3
197+
},
198+
"file_extension": ".py",
199+
"mimetype": "text/x-python",
200+
"name": "python",
201+
"nbconvert_exporter": "python",
202+
"pygments_lexer": "ipython3",
203+
"version": "3.12.1"
204+
}
205+
},
206+
"nbformat": 4,
207+
"nbformat_minor": 5
208+
}

0 commit comments

Comments
 (0)