1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "kernelspec" : {
6
+ "display_name" : " Python 3" ,
7
+ "language" : " python" ,
8
+ "name" : " python3"
9
+ },
10
+ "language_info" : {
11
+ "codemirror_mode" : {
12
+ "name" : " ipython" ,
13
+ "version" : 3
14
+ },
15
+ "file_extension" : " .py" ,
16
+ "mimetype" : " text/x-python" ,
17
+ "name" : " python" ,
18
+ "nbconvert_exporter" : " python" ,
19
+ "pygments_lexer" : " ipython3" ,
20
+ "version" : " 3.6.6"
21
+ },
22
+ "colab" : {
23
+ "name" : " 02-Object Oriented Programming Homework.ipynb" ,
24
+ "provenance" : []
25
+ }
26
+ },
27
+ "cells" : [
28
+ {
29
+ "cell_type" : " markdown" ,
30
+ "metadata" : {
31
+ "id" : " uz3VioCV4m9C"
32
+ },
33
+ "source" : [
34
+ " ___\n " ,
35
+ " \n " ,
36
+ " <a href='https://www.udemy.com/user/joseportilla/'><img src='https://github.com/Pierian-Data/Complete-Python-3-Bootcamp/blob/master/Pierian_Data_Logo.png?raw=1'/></a>\n " ,
37
+ " ___\n " ,
38
+ " <center><em>Content Copyright by Pierian Data</em></center>"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type" : " markdown" ,
43
+ "metadata" : {
44
+ "id" : " AWbfdF_Y4m9D"
45
+ },
46
+ "source" : [
47
+ " # Object Oriented Programming\n " ,
48
+ " ## Homework Assignment\n " ,
49
+ " \n " ,
50
+ " #### Problem 1\n " ,
51
+ " Fill in the Line class methods to accept coordinates as a pair of tuples and return the slope and distance of the line."
52
+ ]
53
+ },
54
+ {
55
+ "cell_type" : " code" ,
56
+ "metadata" : {
57
+ "collapsed" : true ,
58
+ "id" : " WwdyA6ID4m9E"
59
+ },
60
+ "source" : [
61
+ " class Line:\n " ,
62
+ " \n " ,
63
+ " def __init__(self,coor1,coor2):\n " ,
64
+ " self.coor1=coor1\n " ,
65
+ " self.coor2=coor2\n " ,
66
+ " \n " ,
67
+ " def distance(self):\n " ,
68
+ " x1, y1= self.coor1\n " ,
69
+ " x2, y2= self.coor2\n " ,
70
+ " dist= (abs((x2-x1)**2)+((y2-y1)**2))**0.5\n " ,
71
+ " return dist\n " ,
72
+ " \n " ,
73
+ " def slope(self):\n " ,
74
+ " x1, y1= self.coor1\n " ,
75
+ " x2, y2= self.coor2\n " ,
76
+ " slo= (y2-y1)/(x2-x1)\n " ,
77
+ " return slo"
78
+ ],
79
+ "execution_count" : 8 ,
80
+ "outputs" : []
81
+ },
82
+ {
83
+ "cell_type" : " code" ,
84
+ "metadata" : {
85
+ "collapsed" : true ,
86
+ "id" : " 3c2s5Ef74m9E"
87
+ },
88
+ "source" : [
89
+ " # EXAMPLE OUTPUT\n " ,
90
+ " \n " ,
91
+ " coordinate1 = (3,2)\n " ,
92
+ " coordinate2 = (8,10)\n " ,
93
+ " \n " ,
94
+ " li = Line(coordinate1,coordinate2)"
95
+ ],
96
+ "execution_count" : 9 ,
97
+ "outputs" : []
98
+ },
99
+ {
100
+ "cell_type" : " code" ,
101
+ "metadata" : {
102
+ "id" : " yMeFDLTu4m9F" ,
103
+ "outputId" : " 960ba414-7d31-49bf-e992-1f0eb2e1e859"
104
+ },
105
+ "source" : [
106
+ " li.distance()"
107
+ ],
108
+ "execution_count" : null ,
109
+ "outputs" : [
110
+ {
111
+ "output_type" : " execute_result" ,
112
+ "data" : {
113
+ "text/plain" : [
114
+ " 9.433981132056603"
115
+ ]
116
+ },
117
+ "metadata" : {
118
+ "tags" : []
119
+ },
120
+ "execution_count" : 3
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "cell_type" : " code" ,
126
+ "metadata" : {
127
+ "id" : " Q4SIWWLt4m9F" ,
128
+ "outputId" : " fb0801e9-83a7-476a-a755-a1685776f415" ,
129
+ "colab" : {
130
+ "base_uri" : " https://localhost:8080/"
131
+ }
132
+ },
133
+ "source" : [
134
+ " li.slope()"
135
+ ],
136
+ "execution_count" : 10 ,
137
+ "outputs" : [
138
+ {
139
+ "output_type" : " execute_result" ,
140
+ "data" : {
141
+ "text/plain" : [
142
+ " 1.6"
143
+ ]
144
+ },
145
+ "metadata" : {
146
+ "tags" : []
147
+ },
148
+ "execution_count" : 10
149
+ }
150
+ ]
151
+ },
152
+ {
153
+ "cell_type" : " markdown" ,
154
+ "metadata" : {
155
+ "id" : " pUeyuFwi4m9G"
156
+ },
157
+ "source" : [
158
+ " ________\n " ,
159
+ " #### Problem 2"
160
+ ]
161
+ },
162
+ {
163
+ "cell_type" : " markdown" ,
164
+ "metadata" : {
165
+ "id" : " PQ7IXVJr4m9G"
166
+ },
167
+ "source" : [
168
+ " Fill in the class "
169
+ ]
170
+ },
171
+ {
172
+ "cell_type" : " code" ,
173
+ "metadata" : {
174
+ "collapsed" : true ,
175
+ "id" : " XUM8OFIk4m9G"
176
+ },
177
+ "source" : [
178
+ " class Cylinder:\n " ,
179
+ " pi=3.14\n " ,
180
+ " def __init__(self,height=1,radius=1):\n " ,
181
+ " self.height=height\n " ,
182
+ " self.radius=radius\n " ,
183
+ " def volume(self):\n " ,
184
+ " return self.pi*(self.radius)**2*self.height\n " ,
185
+ " \n " ,
186
+ " def surface_area(self):\n " ,
187
+ " pass\n " ,
188
+ " "
189
+ ],
190
+ "execution_count" : 15 ,
191
+ "outputs" : []
192
+ },
193
+ {
194
+ "cell_type" : " code" ,
195
+ "metadata" : {
196
+ "collapsed" : true ,
197
+ "id" : " 8yJ8dKiy4m9H"
198
+ },
199
+ "source" : [
200
+ " # EXAMPLE OUTPUT\n " ,
201
+ " c = Cylinder(2,3)"
202
+ ],
203
+ "execution_count" : 16 ,
204
+ "outputs" : []
205
+ },
206
+ {
207
+ "cell_type" : " code" ,
208
+ "metadata" : {
209
+ "id" : " WRmdD3nZ4m9H" ,
210
+ "outputId" : " c5b5213d-d5ed-4135-bd48-00f1c959a645" ,
211
+ "colab" : {
212
+ "base_uri" : " https://localhost:8080/"
213
+ }
214
+ },
215
+ "source" : [
216
+ " c.volume()"
217
+ ],
218
+ "execution_count" : 17 ,
219
+ "outputs" : [
220
+ {
221
+ "output_type" : " execute_result" ,
222
+ "data" : {
223
+ "text/plain" : [
224
+ " 56.52"
225
+ ]
226
+ },
227
+ "metadata" : {
228
+ "tags" : []
229
+ },
230
+ "execution_count" : 17
231
+ }
232
+ ]
233
+ },
234
+ {
235
+ "cell_type" : " code" ,
236
+ "metadata" : {
237
+ "id" : " dc3Jsr7O4m9H" ,
238
+ "outputId" : " bf3e069f-2e9a-4e1f-ae92-e4ea191621ad"
239
+ },
240
+ "source" : [
241
+ " c.surface_area()"
242
+ ],
243
+ "execution_count" : null ,
244
+ "outputs" : [
245
+ {
246
+ "output_type" : " execute_result" ,
247
+ "data" : {
248
+ "text/plain" : [
249
+ " 94.2"
250
+ ]
251
+ },
252
+ "metadata" : {
253
+ "tags" : []
254
+ },
255
+ "execution_count" : 8
256
+ }
257
+ ]
258
+ }
259
+ ]
260
+ }
0 commit comments