Skip to content

Commit d7534e9

Browse files
Add files via upload
1 parent 120eee3 commit d7534e9

File tree

1 file changed

+80
-6
lines changed

1 file changed

+80
-6
lines changed

Assignment-18.ipynb

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
},
7575
{
7676
"cell_type": "code",
77-
"execution_count": 20,
78-
"id": "6bb76d12",
77+
"execution_count": 4,
78+
"id": "abeae836",
7979
"metadata": {},
8080
"outputs": [
8181
{
@@ -89,14 +89,88 @@
8989
}
9090
],
9191
"source": [
92-
"lst = [1, 2, 3, 4, 5, 6]\n",
93-
"first = lst[0]\n",
94-
"middle = lst[1:-1]\n",
95-
"last = lst[-1]\n",
92+
"lst=[1,2,3,4,5,6]\n",
93+
"first,*middle,last=lst\n",
9694
"print(first)\n",
9795
"print(middle)\n",
9896
"print(last)"
9997
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 1,
102+
"id": "a356c62c",
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"def factorial(n):\n",
107+
" if n==0:\n",
108+
" return 1\n",
109+
" else:\n",
110+
" return n*factorial(n-1)"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": 4,
116+
"id": "858b7aa3",
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"120\n",
124+
"6\n",
125+
"1\n",
126+
"1\n"
127+
]
128+
}
129+
],
130+
"source": [
131+
"print(factorial(5))\n",
132+
"print(factorial(3))\n",
133+
"print(factorial(1))\n",
134+
"print(factorial(0))"
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": 25,
140+
"id": "fa7b25b1",
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"def move_to_end(a,b):\n",
145+
" l = len(a)\n",
146+
" for i in a:\n",
147+
" if i == b:\n",
148+
" a.remove(i)\n",
149+
" a.append(i)\n",
150+
" return a"
151+
]
152+
},
153+
{
154+
"cell_type": "code",
155+
"execution_count": 26,
156+
"id": "01224685",
157+
"metadata": {},
158+
"outputs": [
159+
{
160+
"name": "stdout",
161+
"output_type": "stream",
162+
"text": [
163+
"[3, 2, 4, 4, 1, 1]\n",
164+
"[7, 8, 1, 2, 3, 4, 9]\n",
165+
"['b', 'a', 'a', 'a']\n"
166+
]
167+
}
168+
],
169+
"source": [
170+
"print(move_to_end([1, 3, 2, 4, 4, 1], 1))\n",
171+
"print(move_to_end([7, 8, 9, 1, 2, 3, 4], 9))\n",
172+
"print(move_to_end([\"a\", \"a\", \"a\", \"b\"],\"a\"))"
173+
]
100174
}
101175
],
102176
"metadata": {

0 commit comments

Comments
 (0)