runtime
252 / 500
question 252 Classes & Objects · easy

Checked one value, stored another

Products loaded from the supplier's CSV file crash with TypeError: '<' not supported between instances of 'str' and 'int', and products created in code end up with SKUs like ' spo-11681' even though the SKU check passes. Fix Product.__init__ so it tidies and converts every value, checks the tidy values, and stores exactly what it checked.

ClassProduct(sku, name, price)
Storessku stripped and upper-cased; name stripped; price as a float (it may arrive as text)
RaisesValueError for a SKU that isn't 3 capital letters, a dash and 5 digits, or a negative price

Loading your progress…

Checked one value, stored another — Python practice · Runtime