Skip to content

Commit 293d1ef

Browse files
Completed the Assignment
1 parent f306cdf commit 293d1ef

File tree

1 file changed

+250
-0
lines changed

1 file changed

+250
-0
lines changed

Placement Assignment.ipynb

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "8de0d99e",
6+
"metadata": {},
7+
"source": [
8+
"## Assignment 1"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 31,
14+
"id": "a0b8bc16",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"def readfile(filepath, replacestring):\n",
19+
" with open(filepath,'r+') as f:\n",
20+
" contents = f.read()\n",
21+
" updatedcontent = contents.replace(\"placement\",replacestring)\n",
22+
" return updatedcontent"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 32,
28+
"id": "46f81799",
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": [
34+
"'This is a screening assignment'"
35+
]
36+
},
37+
"execution_count": 32,
38+
"metadata": {},
39+
"output_type": "execute_result"
40+
}
41+
],
42+
"source": [
43+
"readfile('D:/Python Revision/example.txt','screening')"
44+
]
45+
},
46+
{
47+
"cell_type": "markdown",
48+
"id": "730537f8",
49+
"metadata": {},
50+
"source": [
51+
"## Assignment 2: Use of Abstract Class"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 33,
57+
"id": "446a8d31",
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"name": "stdout",
62+
"output_type": "stream",
63+
"text": [
64+
"I have 2 tyres\n",
65+
"I have 4 tyres\n"
66+
]
67+
}
68+
],
69+
"source": [
70+
"# Python program showing\n",
71+
"# abstract base class work\n",
72+
"\n",
73+
"from abc import ABC, abstractmethod\n",
74+
"\n",
75+
"class Vehicle(ABC):\n",
76+
"\n",
77+
" @abstractmethod\n",
78+
" def nooftyres(self):\n",
79+
" pass\n",
80+
"\n",
81+
"class BiCycle(Vehicle):\n",
82+
"\n",
83+
" # overriding abstract method\n",
84+
" def nooftyres(self):\n",
85+
" print(\"I have 2 tyres\")\n",
86+
"\n",
87+
"class Car(Vehicle):\n",
88+
"\n",
89+
" # overriding abstract method\n",
90+
" def nooftyres(self):\n",
91+
" print(\"I have 4 tyres\")\n",
92+
"\n",
93+
"\n",
94+
"# Driver code\n",
95+
"B = BiCycle()\n",
96+
"B.nooftyres()\n",
97+
"\n",
98+
"C = Car()\n",
99+
"C.nooftyres()"
100+
]
101+
},
102+
{
103+
"cell_type": "markdown",
104+
"id": "0890df32",
105+
"metadata": {},
106+
"source": [
107+
"## Multiple Inheritance using decorator"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": 71,
113+
"id": "5a96f9b2",
114+
"metadata": {},
115+
"outputs": [],
116+
"source": [
117+
"class Person: \n",
118+
" def __init__(self,name,age):\n",
119+
" self.name=name\n",
120+
" self.age=age\n",
121+
"\n",
122+
" @property\n",
123+
" def getname(self):\n",
124+
" return self.name\n",
125+
" \n",
126+
" @getname.setter\n",
127+
" def setname(self,name):\n",
128+
" self.name = name"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": 61,
134+
"id": "4479c504",
135+
"metadata": {},
136+
"outputs": [],
137+
"source": [
138+
"class Student:\n",
139+
" def __init__(self,roll,per):\n",
140+
" self.roll=roll\n",
141+
" self.per=per\n",
142+
" def getroll(self):\n",
143+
" return self.roll\n",
144+
" def getper(self):\n",
145+
" return self.per"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": 64,
151+
"id": "fbee8fb0",
152+
"metadata": {},
153+
"outputs": [],
154+
"source": [
155+
"class ScienceStudent(Person,Student):\n",
156+
" def __init__(self,name,age,roll,per,stream):\n",
157+
" Person.__init__(self,name,age)\n",
158+
" Student.__init__(self,roll,per)\n",
159+
" self.stream=stream\n",
160+
" def getstream(self):\n",
161+
" return self.stream"
162+
]
163+
},
164+
{
165+
"cell_type": "code",
166+
"execution_count": 65,
167+
"id": "6c9c0032",
168+
"metadata": {},
169+
"outputs": [],
170+
"source": [
171+
"ms=ScienceStudent(\"Suresh\",19,203,89.4,\"maths\",)"
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": 67,
177+
"id": "eae0e715",
178+
"metadata": {},
179+
"outputs": [
180+
{
181+
"data": {
182+
"text/plain": [
183+
"'Suresh'"
184+
]
185+
},
186+
"execution_count": 67,
187+
"metadata": {},
188+
"output_type": "execute_result"
189+
}
190+
],
191+
"source": [
192+
"## use of decorator \n",
193+
"ms.name"
194+
]
195+
},
196+
{
197+
"cell_type": "code",
198+
"execution_count": 73,
199+
"id": "99fddb6f",
200+
"metadata": {},
201+
"outputs": [],
202+
"source": [
203+
"## setter function\n",
204+
"ms.name = 'Kamlesh'"
205+
]
206+
},
207+
{
208+
"cell_type": "code",
209+
"execution_count": 74,
210+
"id": "eb1681e2",
211+
"metadata": {},
212+
"outputs": [
213+
{
214+
"data": {
215+
"text/plain": [
216+
"'Kamlesh'"
217+
]
218+
},
219+
"execution_count": 74,
220+
"metadata": {},
221+
"output_type": "execute_result"
222+
}
223+
],
224+
"source": [
225+
"ms.name"
226+
]
227+
}
228+
],
229+
"metadata": {
230+
"kernelspec": {
231+
"display_name": "Python 3",
232+
"language": "python",
233+
"name": "python3"
234+
},
235+
"language_info": {
236+
"codemirror_mode": {
237+
"name": "ipython",
238+
"version": 3
239+
},
240+
"file_extension": ".py",
241+
"mimetype": "text/x-python",
242+
"name": "python",
243+
"nbconvert_exporter": "python",
244+
"pygments_lexer": "ipython3",
245+
"version": "3.7.1"
246+
}
247+
},
248+
"nbformat": 4,
249+
"nbformat_minor": 5
250+
}

0 commit comments

Comments
 (0)