13.17. Exercises
13-1. Programming. Name some benefits of object-oriented programming over older forms of programming.
13-2. Functions vs. Methods. What are the differences between functions and methods?
13-3. Customizing Classes. Create a class to format floating point values to monetary amounts. In this exercise, we will use United States currency, but feel free to implement your own.
Preliminary work: Create a function called dollarize() which takes a floating point value and returns that value as a string properly formatted with symbols and rounded to obtain a financial amount. For example: dollarize(1234567.8901) ⇒ '$1,234,567.89' The dollarize() function should allow for commas, such as 1,000,000, and dollar signs. Any negative sign should ...
Get Core Python Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.