Skip to content

Commit 9b45ea3

Browse files
committed
Python Classes: Final QA
1 parent 4736825 commit 9b45ea3

File tree

13 files changed

+50
-87
lines changed

13 files changed

+50
-87
lines changed

python-class/aircrafts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def __init__(self, thrust, lift, max_speed):
44
self.lift = lift
55
self.max_speed = max_speed
66

7-
def technical_specs(self):
7+
def show_technical_specs(self):
88
print(f"Thrust: {self.thrust} kW")
99
print(f"Lift: {self.lift} kg")
1010
print(f"Max speed: {self.max_speed} km/h")
@@ -15,6 +15,6 @@ def __init__(self, thrust, lift, max_speed, num_rotors):
1515
super().__init__(thrust, lift, max_speed)
1616
self.num_rotors = num_rotors
1717

18-
def technical_specs(self):
19-
super().technical_specs()
18+
def show_technical_specs(self):
19+
super().show_technical_specs()
2020
print(f"Number of rotors: {self.num_rotors}")

python-class/crafts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def start(self):
1010
def stop(self):
1111
print("Stopping the engine...")
1212

13-
def technical_specs(self):
13+
def show_technical_specs(self):
1414
print(f"Make: {self.make}")
1515
print(f"Model: {self.model}")
1616
print(f"Color: {self.color}")

python-class/employee.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ def birth_date(self):
1616
def birth_date(self, value):
1717
self._birth_date = datetime.fromisoformat(value)
1818

19-
def age(self):
19+
def compute_age(self):
2020
today = datetime.today()
2121
age = today.year - self.birth_date.year
2222
birthday = datetime(
23-
today.year, self.birth_date.month, self.birth_date.day
23+
today.year,
24+
self.birth_date.month,
25+
self.birth_date.day
2426
)
2527
if today < birthday:
2628
age -= 1
@@ -31,7 +33,7 @@ def from_dict(cls, data_dict):
3133
return cls(**data_dict)
3234

3335
def __str__(self):
34-
return f"{self.name} is {self.age()} years old"
36+
return f"{self.name} is {self.compute_age()} years old"
3537

3638
def __repr__(self):
3739
return (

python-class/getattr.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

python-class/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def to_pickle(self):
1616
return pickle.dumps(self.__dict__)
1717

1818

19-
class Employee(Person, SerializerMixin):
19+
class Employee(SerializerMixin, Person):
2020
def __init__(self, name, age, salary):
2121
super().__init__(name, age)
2222
self.salary = salary

python-class/person.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Setters and getters
1+
# Getters and setters
22
# class Person:
33
# def __init__(self, name):
44
# self.set_name(name)
55

6-
# def name(self):
6+
# def get_name(self):
77
# return self._name
88

99
# def set_name(self, value):
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ def __init__(self, x, y):
2525
# return cls(*sequence)
2626

2727
# @staticmethod
28-
# def intro_msg(name):
28+
# def show_intro_message(name):
2929
# print(f"Hey {name}! This is your 3D Point!")
3030

3131
# def __repr__(self):
3232
# return f"{type(self).__name__}({self.x}, {self.y}, {self.z})"
3333

3434

3535
# Dataclass
36-
@dataclass
37-
class ThreeDPoint:
38-
x: int | float
39-
y: int | float
40-
z: int | float
41-
42-
@classmethod
43-
def from_sequence(cls, sequence):
44-
return cls(*sequence)
45-
46-
@staticmethod
47-
def intro_msg(name):
48-
print(f"Hey {name}! This is your 3D Point!")
36+
# @dataclass
37+
# class ThreeDPoint:
38+
# x: int | float
39+
# y: int | float
40+
# z: int | float
41+
42+
# @classmethod
43+
# def from_sequence(cls, sequence):
44+
# return cls(*sequence)
45+
46+
# @staticmethod
47+
# def show_intro_message(name):
48+
# print(f"Hey {name}! This is your 3D Point!")

python-class/shape_property.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

python-class/shapes_abc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@
44

55
class Shape(ABC):
66
@abstractmethod
7-
def area(self):
7+
def get_area(self):
88
pass
99

1010
@abstractmethod
11-
def perimeter(self):
11+
def get_perimeter(self):
1212
pass
1313

1414

1515
class Circle(Shape):
1616
def __init__(self, radius):
1717
self.radius = radius
1818

19-
def area(self):
19+
def get_area(self):
2020
return pi * self.radius**2
2121

22-
def perimeter(self):
22+
def get_perimeter(self):
2323
return 2 * pi * self.radius
2424

2525

2626
class Square(Shape):
2727
def __init__(self, side):
2828
self.side = side
2929

30-
def area(self):
30+
def get_area(self):
3131
return self.side**2
3232

33-
def perimeter(self):
33+
def get_perimeter(self):
3434
return 4 * self.side

0 commit comments

Comments
 (0)