1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "name" : " OOP_TASK05.ipynb" ,
7
+ "provenance" : [],
8
+ "authorship_tag" : " ABX9TyMlcyzv7wTbIlPyGUvR5gr6" ,
9
+ "include_colab_link" : true
10
+ },
11
+ "kernelspec" : {
12
+ "name" : " python3" ,
13
+ "display_name" : " Python 3"
14
+ },
15
+ "language_info" : {
16
+ "name" : " python"
17
+ }
18
+ },
19
+ "cells" : [
20
+ {
21
+ "cell_type" : " markdown" ,
22
+ "metadata" : {
23
+ "id" : " view-in-github" ,
24
+ "colab_type" : " text"
25
+ },
26
+ "source" : [
27
+ " <a href=\" https://colab.research.google.com/github/Arjun-08/OOP-LabAssignment1/blob/main/OOP_TASK05.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type" : " markdown" ,
32
+ "metadata" : {
33
+ "id" : " 3NfiTIeLGq4L"
34
+ },
35
+ "source" : [
36
+ " # PROBLEM 1\n "
37
+ ]
38
+ },
39
+ {
40
+ "cell_type" : " code" ,
41
+ "metadata" : {
42
+ "colab" : {
43
+ "base_uri" : " https://localhost:8080/"
44
+ },
45
+ "id" : " eg5d0G2-GsMf" ,
46
+ "outputId" : " 5eff7933-7074-4195-b396-c7653a5304d4"
47
+ },
48
+ "source" : [
49
+ " from abc import ABC, abstractmethod\n " ,
50
+ " import math\n " ,
51
+ " class Shape(ABC):\n " ,
52
+ " def __init__(self, shape):\n " ,
53
+ " self.shape = shape\n " ,
54
+ " \n " ,
55
+ " @abstractmethod\n " ,
56
+ " def area(self):\n " ,
57
+ " pass\n " ,
58
+ " \n " ,
59
+ " class Rectangle(Shape):\n " ,
60
+ " def __init__(self, length, breadth):\n " ,
61
+ " Shape.__init__(self, 'Rectangle')\n " ,
62
+ " self.length = length\n " ,
63
+ " self.breadth = breadth\n " ,
64
+ " \n " ,
65
+ " def area(self):\n " ,
66
+ " return self.length*self.breadth\n " ,
67
+ " \n " ,
68
+ " class Circle(Shape):\n " ,
69
+ " def __init__(self, radius):\n " ,
70
+ " Shape.__init__(self, 'Circle')\n " ,
71
+ " self.radius = radius\n " ,
72
+ " \n " ,
73
+ " def area(self):\n " ,
74
+ " return round((math.pi)*(self.radius**2),2)\n " ,
75
+ " \n " ,
76
+ " class Square(Shape):\n " ,
77
+ " def __init__(self, side):\n " ,
78
+ " Shape.__init__(self, 'Square')\n " ,
79
+ " self.side = side\n " ,
80
+ " \n " ,
81
+ " def area(self):\n " ,
82
+ " return self.side*self.side\n " ,
83
+ " \n " ,
84
+ " sq = Square(9)\n " ,
85
+ " print(\" Area of square :\" , sq.area())\n " ,
86
+ " rect = Rectangle(6,7)\n " ,
87
+ " print(\" Area of rectangle:\" , rect.area())\n " ,
88
+ " c = Circle(8)\n " ,
89
+ " print(\" Area of circle :\" , c.area())"
90
+ ],
91
+ "execution_count" : 13 ,
92
+ "outputs" : [
93
+ {
94
+ "output_type" : " stream" ,
95
+ "name" : " stdout" ,
96
+ "text" : [
97
+ " Area of square : 81\n " ,
98
+ " Area of rectangle: 42\n " ,
99
+ " Area of circle : 201.06\n "
100
+ ]
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "cell_type" : " markdown" ,
106
+ "metadata" : {
107
+ "id" : " qgUiclcAGxue"
108
+ },
109
+ "source" : [
110
+ " # PROBLEM 2"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type" : " code" ,
115
+ "metadata" : {
116
+ "colab" : {
117
+ "base_uri" : " https://localhost:8080/"
118
+ },
119
+ "id" : " 6Hf1-qwkG1v0" ,
120
+ "outputId" : " 085dd026-049b-4cb0-ba9f-e2cf1b17bf7f"
121
+ },
122
+ "source" : [
123
+ " class Travel:\n " ,
124
+ " \n " ,
125
+ " def __init__(self, travel):\n " ,
126
+ " self.travel = travel\n " ,
127
+ " \n " ,
128
+ " def number_of_passangers(self):\n " ,
129
+ " pass\n " ,
130
+ " \n " ,
131
+ " def distance(self):\n " ,
132
+ " pass\n " ,
133
+ " \n " ,
134
+ " def mode(self):\n " ,
135
+ " pass\n " ,
136
+ " \n " ,
137
+ " class train(Travel):\n " ,
138
+ " \n " ,
139
+ " def __init__(self, total_passangers):\n " ,
140
+ " self.total_passangers = total_passangers\n " ,
141
+ " \n " ,
142
+ " def cost_of_transport(self):\n " ,
143
+ " print('cost of transport by train is',self.total_passangers*60)\n " ,
144
+ " \n " ,
145
+ " class bus(Travel):\n " ,
146
+ " \n " ,
147
+ " def __init__(self, total_passangers):\n " ,
148
+ " self.total_passangers = total_passangers\n " ,
149
+ " \n " ,
150
+ " def cost_of_transport(self):\n " ,
151
+ " print('cost of transport by bus is',self.total_passangers*100)\n " ,
152
+ " \n " ,
153
+ " mode1 = train(12)\n " ,
154
+ " mode1.cost_of_transport()\n " ,
155
+ " \n " ,
156
+ " mode2 = bus(12)\n " ,
157
+ " mode2.cost_of_transport()"
158
+ ],
159
+ "execution_count" : 19 ,
160
+ "outputs" : [
161
+ {
162
+ "output_type" : " stream" ,
163
+ "name" : " stdout" ,
164
+ "text" : [
165
+ " cost of transport by train is 720\n " ,
166
+ " cost of transport by train is 1200\n "
167
+ ]
168
+ }
169
+ ]
170
+ },
171
+ {
172
+ "cell_type" : " markdown" ,
173
+ "metadata" : {
174
+ "id" : " G1gZNZKXG4-s"
175
+ },
176
+ "source" : [
177
+ " # PROBLEM 3"
178
+ ]
179
+ },
180
+ {
181
+ "cell_type" : " code" ,
182
+ "metadata" : {
183
+ "colab" : {
184
+ "base_uri" : " https://localhost:8080/"
185
+ },
186
+ "id" : " 6ijSzTKTG7iA" ,
187
+ "outputId" : " fac98c2c-3338-4adf-b005-e2381b4ecd7c"
188
+ },
189
+ "source" : [
190
+ " \n " ,
191
+ " class car:\n " ,
192
+ " def __init__(self,carnumber):\n " ,
193
+ " self.carnumber=carnumber\n " ,
194
+ " c1=car(1998)\n " ,
195
+ " c2=car(2002)\n " ,
196
+ " print('the model number of c1 is',c1.carnumber)\n " ,
197
+ " print('the model number of c2 is',c2.carnumber)\n " ,
198
+ " print('--------------------------------')\n " ,
199
+ " def carnumswap():\n " ,
200
+ " c1.carnumber,c2.carnumber=c2.carnumber,c1.carnumber\n " ,
201
+ " print(\" the model number of c1 is \" ,c1.carnumber)\n " ,
202
+ " print(\" the model number of c2 is \" ,c2.carnumber)\n " ,
203
+ " carnumswap()"
204
+ ],
205
+ "execution_count" : 24 ,
206
+ "outputs" : [
207
+ {
208
+ "output_type" : " stream" ,
209
+ "name" : " stdout" ,
210
+ "text" : [
211
+ " the model number of c1 is 1998\n " ,
212
+ " the model number of c2 is 2002\n " ,
213
+ " --------------------------------\n " ,
214
+ " the model number of c1 is 2002\n " ,
215
+ " the model number of c2 is 1998\n "
216
+ ]
217
+ }
218
+ ]
219
+ }
220
+ ]
221
+ }
0 commit comments