Objective
Create a Python program with an immutable dataclass (frozen=True) and create modified versions with replace.
Instructions
- Import
dataclass,replaceandFrozenInstanceErrorfromdataclasses. Define@dataclass(frozen=True) class Coordinatewithlat: intandlon: int. - Read a line with two integers,
lat lon, and create the coordinate. - Show
Original:followed by the object. Try to doc.lat = 0inside atry; ifFrozenInstanceErroris raised, showCannot be modified. - Create a new coordinate with
replace(c, lat=c.lat + 1)and showNew:followed by the object.
10 20
Original: Coordinate(lat=10, lon=20)
Cannot be modified
New: Coordinate(lat=11, lon=20)
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise