Objective
Create a Python program with your first dataclass: a class that generates its own constructor and its representation.
Instructions
- Import
dataclassfromdataclassesand define@dataclass class Pointwith two integer attributes,xandy. - Add the method
distance_to_origin(self), which returns(x ** 2 + y ** 2) ** 0.5. - Read a line with two integers, create the point and show the object itself with
print(point)and, on the next line,Distance: Dwith 2 decimals.
3 4
Point(x=3, y=4)
Distance: 5.00
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise