Exercises

  1. 10.1 (What’s Wrong with This Code?) What is wrong with the code in the following IPython session?

    In [1]: try:
       ...:     raise RuntimeError()
       ...: except Exception:
       ...:     print('An Exception occurred')
       ...: except RuntimeError:
       ...:     print('A RuntimeError occurred')
       ...:
    An Exception occurred
  2. 10.2 (Account Class with Read-Only Properties) Modify Section 10.2.2’s Account class to provide read-only properties for the name and balance. Rename the class attributes with single leading underscores. Re-execute Section 10.2.2’s IPython session to test your updated class. To show that name and balance are read-only, try to assign new values to them.

  3. 10.3 (Time Class Enhancement) Modify Section 10.4.2’s Time class to provide a read-only property ...

Get Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud 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.