Witam. Mam problem z moim programem a mianowicie po podaniu litery w inpucie program się wywala. W zadaniu jest napisane że mam kontrolować czy dane są poprawne za pomocą właściwości. Jednak jakby w ogóle program tam nie wchodzi. Proszę o pomoc.
import math
class Point:
def __init__(self, x, y):
self._x = x
self._y = y
@property
def x(self):
return self._x
@x.setter
def x(self, x):
print("x setter")
if not isinstance(x, int):
raise TypeError(f"{x} nie jest int-em")
self._x = x
@property
def y(self):
return self._y
@y.setter
def y(self, y):
print("y setter")
if not isinstance(y, int):
raise TypeError(f"{y} nie jest int-em")
self._y = y
def __str__(self):
return "Wspołrzędna x: {0.x}\tWspołrzędna y: {0.y}".format(self)
def __repr__(self):
return f"{self.__class__.__name__}(x:{self.x},y:{self.y})"
def __eq__(self, other):
if self.__class__.__name__ == other.__class__.__name__:
return self.x == other.x and self.y == other.y
raise TypeError("To nie jest obiekt klasy Point")
def distance_from_origin(self, x, y):
odl = math.sqrt((0 - x) ** 2 + (0 - y) ** 2)
return odl
class Circle(Point):
def __init__(self, x, y, radius):
super(Circle, self).__init__(x, y)
self.radius = radius
@property
def radius(self):
return self._radius
@radius.setter
def radius(self, radius):
if radius < 0:
raise ValueError('Promień powinien być wiekszy od 0')
self._radius = radius
def __repr__(self):
return f"{self.__class__.__name__}(x:{self.x},y:{self.y},promień:{self.radius})"
def __str__(self):
return "Wspołrzędna okręgu x: {0.x}\tWspołrzędna okręgu y: {0.y}\tPromień okręgu: {0.radius}".format(self)
def area(self):
pole = (math.pi * (self.radius ** 2))
return pole
def circumference(self):
obw = 2 * math.pi * self.radius
return obw
def edge_distance_from_origin(self):
odl = math.sqrt((0 - self.x) ** 2 + (0 - self.y) ** 2)
brzeg = odl - self.radius
return brzeg
def __eq__(self, other):
super().__eq__(other)
if self.__class__.__name__ == other.__class__.__name__:
return self.radius == other.radius
raise TypeError("To nie jest obiekt klasy Circle")
if __name__ == '__main__':
x = int(input("podaj współrzedna x: "))
y = int(input("podaj współrzedna y: "))
wspol = Point(x, y)
wspol2 = Point(5, 7)
okrag = Circle(5, 5, 5)
okrag1 = Circle(3, 3, 5)
print(wspol) # str
print(repr(wspol)) # repr
print(okrag)
print(repr(okrag))
print("Odleglosc od srodka osi współrzędnych:", round(wspol.distance_from_origin(x, y), 2))
print(wspol == wspol2)
print(round(okrag.area(), 2))
print("Odleglosc brzegu koła od srodka osi współrzędnych:", round(okrag.edge_distance_from_origin(), 2))
print(okrag == okrag1)