Skip to content

Commit df40416

Browse files
committed
My commitment to the object oriented programming homework
1 parent 4d75055 commit df40416

File tree

2 files changed

+68
-42
lines changed

2 files changed

+68
-42
lines changed

05-Object Oriented Programming/.ipynb_checkpoints/02-Object Oriented Programming Homework-checkpoint.ipynb

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": 1,
16+
"execution_count": 10,
1717
"metadata": {},
1818
"outputs": [],
1919
"source": [
20+
"import math\n",
21+
"\n",
2022
"class Line:\n",
2123
" \n",
2224
" def __init__(self,coor1,coor2):\n",
23-
" pass\n",
25+
" self.coor1 = coor1\n",
26+
" self.coor2 = coor2\n",
2427
" \n",
2528
" def distance(self):\n",
26-
" pass\n",
29+
" return math.sqrt(((self.coor2[0]-self.coor1[0])**2) + ((self.coor2[1]-self.coor1[1])**2))\n",
2730
" \n",
2831
" def slope(self):\n",
29-
" pass"
32+
" return (self.coor2[1]-self.coor1[1])/(self.coor2[0]-self.coor1[0])"
3033
]
3134
},
3235
{
3336
"cell_type": "code",
34-
"execution_count": 2,
37+
"execution_count": 11,
3538
"metadata": {},
3639
"outputs": [],
3740
"source": [
@@ -45,7 +48,7 @@
4548
},
4649
{
4750
"cell_type": "code",
48-
"execution_count": 3,
51+
"execution_count": 12,
4952
"metadata": {},
5053
"outputs": [
5154
{
@@ -54,7 +57,7 @@
5457
"9.433981132056603"
5558
]
5659
},
57-
"execution_count": 3,
60+
"execution_count": 12,
5861
"metadata": {},
5962
"output_type": "execute_result"
6063
}
@@ -65,7 +68,7 @@
6568
},
6669
{
6770
"cell_type": "code",
68-
"execution_count": 4,
71+
"execution_count": 13,
6972
"metadata": {},
7073
"outputs": [
7174
{
@@ -74,7 +77,7 @@
7477
"1.6"
7578
]
7679
},
77-
"execution_count": 4,
80+
"execution_count": 13,
7881
"metadata": {},
7982
"output_type": "execute_result"
8083
}
@@ -100,25 +103,28 @@
100103
},
101104
{
102105
"cell_type": "code",
103-
"execution_count": 5,
106+
"execution_count": 15,
104107
"metadata": {},
105108
"outputs": [],
106109
"source": [
110+
"import math\n",
111+
"\n",
107112
"class Cylinder:\n",
108113
" \n",
109114
" def __init__(self,height=1,radius=1):\n",
110-
" pass\n",
115+
" self.height = height\n",
116+
" self.radius = radius\n",
111117
" \n",
112118
" def volume(self):\n",
113-
" pass\n",
119+
" return (math.pi*(self.radius**2))*self.height\n",
114120
" \n",
115121
" def surface_area(self):\n",
116-
" pass"
122+
" return ((math.pi*(self.radius**2)*2)+((2*math.pi*self.radius)*self.height))"
117123
]
118124
},
119125
{
120126
"cell_type": "code",
121-
"execution_count": 6,
127+
"execution_count": 16,
122128
"metadata": {},
123129
"outputs": [],
124130
"source": [
@@ -128,16 +134,16 @@
128134
},
129135
{
130136
"cell_type": "code",
131-
"execution_count": 7,
137+
"execution_count": 17,
132138
"metadata": {},
133139
"outputs": [
134140
{
135141
"data": {
136142
"text/plain": [
137-
"56.52"
143+
"56.548667764616276"
138144
]
139145
},
140-
"execution_count": 7,
146+
"execution_count": 17,
141147
"metadata": {},
142148
"output_type": "execute_result"
143149
}
@@ -148,23 +154,30 @@
148154
},
149155
{
150156
"cell_type": "code",
151-
"execution_count": 8,
157+
"execution_count": 18,
152158
"metadata": {},
153159
"outputs": [
154160
{
155161
"data": {
156162
"text/plain": [
157-
"94.2"
163+
"94.24777960769379"
158164
]
159165
},
160-
"execution_count": 8,
166+
"execution_count": 18,
161167
"metadata": {},
162168
"output_type": "execute_result"
163169
}
164170
],
165171
"source": [
166172
"c.surface_area()"
167173
]
174+
},
175+
{
176+
"cell_type": "code",
177+
"execution_count": null,
178+
"metadata": {},
179+
"outputs": [],
180+
"source": []
168181
}
169182
],
170183
"metadata": {
@@ -183,7 +196,7 @@
183196
"name": "python",
184197
"nbconvert_exporter": "python",
185198
"pygments_lexer": "ipython3",
186-
"version": "3.6.2"
199+
"version": "3.6.4"
187200
}
188201
},
189202
"nbformat": 4,

05-Object Oriented Programming/02-Object Oriented Programming Homework.ipynb

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": 1,
16+
"execution_count": 10,
1717
"metadata": {},
1818
"outputs": [],
1919
"source": [
20+
"import math\n",
21+
"\n",
2022
"class Line:\n",
2123
" \n",
2224
" def __init__(self,coor1,coor2):\n",
23-
" pass\n",
25+
" self.coor1 = coor1\n",
26+
" self.coor2 = coor2\n",
2427
" \n",
2528
" def distance(self):\n",
26-
" pass\n",
29+
" return math.sqrt(((self.coor2[0]-self.coor1[0])**2) + ((self.coor2[1]-self.coor1[1])**2))\n",
2730
" \n",
2831
" def slope(self):\n",
29-
" pass"
32+
" return (self.coor2[1]-self.coor1[1])/(self.coor2[0]-self.coor1[0])"
3033
]
3134
},
3235
{
3336
"cell_type": "code",
34-
"execution_count": 2,
37+
"execution_count": 11,
3538
"metadata": {},
3639
"outputs": [],
3740
"source": [
@@ -45,7 +48,7 @@
4548
},
4649
{
4750
"cell_type": "code",
48-
"execution_count": 3,
51+
"execution_count": 12,
4952
"metadata": {},
5053
"outputs": [
5154
{
@@ -54,7 +57,7 @@
5457
"9.433981132056603"
5558
]
5659
},
57-
"execution_count": 3,
60+
"execution_count": 12,
5861
"metadata": {},
5962
"output_type": "execute_result"
6063
}
@@ -65,7 +68,7 @@
6568
},
6669
{
6770
"cell_type": "code",
68-
"execution_count": 4,
71+
"execution_count": 13,
6972
"metadata": {},
7073
"outputs": [
7174
{
@@ -74,7 +77,7 @@
7477
"1.6"
7578
]
7679
},
77-
"execution_count": 4,
80+
"execution_count": 13,
7881
"metadata": {},
7982
"output_type": "execute_result"
8083
}
@@ -100,25 +103,28 @@
100103
},
101104
{
102105
"cell_type": "code",
103-
"execution_count": 5,
106+
"execution_count": 15,
104107
"metadata": {},
105108
"outputs": [],
106109
"source": [
110+
"import math\n",
111+
"\n",
107112
"class Cylinder:\n",
108113
" \n",
109114
" def __init__(self,height=1,radius=1):\n",
110-
" pass\n",
115+
" self.height = height\n",
116+
" self.radius = radius\n",
111117
" \n",
112118
" def volume(self):\n",
113-
" pass\n",
119+
" return (math.pi*(self.radius**2))*self.height\n",
114120
" \n",
115121
" def surface_area(self):\n",
116-
" pass"
122+
" return ((math.pi*(self.radius**2)*2)+((2*math.pi*self.radius)*self.height))"
117123
]
118124
},
119125
{
120126
"cell_type": "code",
121-
"execution_count": 6,
127+
"execution_count": 16,
122128
"metadata": {},
123129
"outputs": [],
124130
"source": [
@@ -128,16 +134,16 @@
128134
},
129135
{
130136
"cell_type": "code",
131-
"execution_count": 7,
137+
"execution_count": 17,
132138
"metadata": {},
133139
"outputs": [
134140
{
135141
"data": {
136142
"text/plain": [
137-
"56.52"
143+
"56.548667764616276"
138144
]
139145
},
140-
"execution_count": 7,
146+
"execution_count": 17,
141147
"metadata": {},
142148
"output_type": "execute_result"
143149
}
@@ -148,23 +154,30 @@
148154
},
149155
{
150156
"cell_type": "code",
151-
"execution_count": 8,
157+
"execution_count": 18,
152158
"metadata": {},
153159
"outputs": [
154160
{
155161
"data": {
156162
"text/plain": [
157-
"94.2"
163+
"94.24777960769379"
158164
]
159165
},
160-
"execution_count": 8,
166+
"execution_count": 18,
161167
"metadata": {},
162168
"output_type": "execute_result"
163169
}
164170
],
165171
"source": [
166172
"c.surface_area()"
167173
]
174+
},
175+
{
176+
"cell_type": "code",
177+
"execution_count": null,
178+
"metadata": {},
179+
"outputs": [],
180+
"source": []
168181
}
169182
],
170183
"metadata": {
@@ -183,7 +196,7 @@
183196
"name": "python",
184197
"nbconvert_exporter": "python",
185198
"pygments_lexer": "ipython3",
186-
"version": "3.6.2"
199+
"version": "3.6.4"
187200
}
188201
},
189202
"nbformat": 4,

0 commit comments

Comments
 (0)