Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A class Note has an attribute rupees. Write __lt__ and __str__ so that sorted puts a list of notes in order and print shows Rs 50. Show the sorted list of notes of 50, 5 and 20.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. sorted only asks "which comes first?", so __lt__ is enough. __str__ returns a text.
Check. The output is Rs 5, Rs 20, Rs 50. __str__ returns the text, and print shows it.
Answer: Rs 5, Rs 20 and Rs 50.
Log in to join the discussion.
Loading…