Skip to content
C

Convert a Class to a Dataclass

Easypython

Rewrite a Product class (with name, price, and an in_stock flag defaulting to True) using @dataclass, then construct one from the given input and print it.

Approach: read a name and price, then an optional instock override ("True", "False", or a blank line meaning "use the default"), construct the dataclass accordingly, and print it — relying on @dataclass's auto-generated repr_.

Input: Three lines: name, price, and an in_stock override ("True", "False", or a blank line to use the default).

Output: One line: the dataclass instance's default repr, e.g. Product(name='Shirt', price=500.0, in_stock=True).

Input (stdin)

Output

Run your code to see output here...