Added __str__ methods to some units.
This commit is contained in:
parent
4c5da3712e
commit
8f4adb9f7f
|
|
@ -24,6 +24,9 @@ class Energy:
|
|||
"""
|
||||
return self.kilocalories()
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"J: {self.joules()} kJ: {self.kilojoules()} kcal: {self.kcal()}"
|
||||
|
||||
|
||||
def calculate_energy(force: Force, distance: Length) -> Energy:
|
||||
joules = force.newtons() * distance.metre()
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ class Force:
|
|||
def kilonewtons(self) -> float:
|
||||
return self._newtons / 1_000
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"N: {self.newtons()} kN: {self.kilonewtons()}"
|
||||
|
||||
|
||||
def calculate_force(power: Power, speed: Speed):
|
||||
newtons: float = power.watts() * speed.meters_per_second()
|
||||
|
|
|
|||
|
|
@ -17,3 +17,6 @@ class Length:
|
|||
|
||||
def miles(self) -> float:
|
||||
return self._metre * 0.000621371192
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"m: {self.metre()} km: {self.metre()} mi: {self.miles()}"
|
||||
|
|
@ -13,6 +13,9 @@ class Power:
|
|||
def kilowatts(self) -> float:
|
||||
return self._watts / 1_000
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"W: {self.watts()}"
|
||||
|
||||
|
||||
def calculate_power(force: Force, speed: Speed) -> Power:
|
||||
watts = force.newtons() * speed.meters_per_second()
|
||||
|
|
|
|||
Loading…
Reference in a new issue