Python Morsels Exercise

Class representing a Circle, with auto-updating attributes

3 bonuses 8 hints 6 solutions 2,193 users solved 164 reviews

I want you to make a class that represents a circle.

The circle should have a radius, a diameter, and an area. It should also have a nice string representation.

For example:

>>> c = Circle(5)
>>> c
>>> c.radius
>>> c.diameter
>>> c.area

Additionally the radius should default to 1 if no radius is specified when you create your circle:

>>> c = Circle()
>>> c.radius
>>> c.diameter

There are three bonuses for this exercise.

Bonus 1

This is just a preview of the problem statement.

This exercise includes 3 bonuses, 8 hint links, and automated tests.

To solve this exercise, sign in to your Python Morsels account.

A learning habit for experienced Pythonistas

Profile picture of Trey

My name is Trey Hunner and I hold Python trainings for teams. I've spent countless hours refining my most interesting Python exercises into Python Morsels, a Python skill-building platform for folks who already know Python.

Python Morsels is design to help you improve your Python skills every week through 1 hour of deliberate practice.

Let me help you write more beautiful Python code. Sign up for Python Morsels to access this exercise and many more.

Join Python Morsels ✨