-
Notifications
You must be signed in to change notification settings - Fork 0
/
naming_challenge.py
77 lines (64 loc) · 1.99 KB
/
naming_challenge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#################### Bad naming ###################
#
#
# class Point:
# def __init__(self, coordX, coordY):
# self.coordX = coordX
# self.coordY = coordY
#
#
# class Rectangle:
# def __init__(self, starting_point, broad, high):
# self.starting_point = starting_point
# self.broad = broad
# self.high = high
#
# def area(self):
# return self.broad * self.high
#
# def end_points(self):
# top_right = self.starting_point.coordX + self.broad
# bottom_left = self.starting_point.coordY + self.high
# print('Starting Point (X)): ' + str(self.starting_point.coordX))
# print('Starting Point (Y)): ' + str(self.starting_point.coordY))
# print('End Point X-Axis (Top Right): ' + str(top_right))
# print('End Point Y-Axis (Bottom Left): ' + str(bottom_left))
#
#
# def build_stuff():
# main_point = Point(50, 100)
# rect = Rectangle(main_point, 90, 10)
#
# return rect
#
#
# my_rect = build_stuff()
#
# print(my_rect.area())
# my_rect.end_points()
################### Better naming #########################
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
class Rectangle:
def __init__(self, origin, width, height):
self.origin = origin
self.width = width
self.height = height
def get_area(self):
return self.width * self.height
def print_coordinates(self):
top_right = self.origin.x + self.width
bottom_left = self.origin.y + self.height
print('Starting Point (X)): ' + str(self.origin.x))
print('Starting Point (Y)): ' + str(self.origin.y))
print('End Point X-Axis (Top Right): ' + str(top_right))
print('End Point Y-Axis (Bottom Left): ' + str(bottom_left))
def build_rectangle():
rectangle_origin = Point(50, 100)
rectangle = Rectangle(rectangle_origin, 90, 10)
return rectangle
rectangle = build_rectangle()
print(rectangle.get_area())
rectangle.print_coordinates()