Implementation: In the solarsystem.py module, implement the SolarSystem class as described in Section 10.5. \ Your SolarSystem class should include these methods: __init__, add_planet, show_planets. You can assume that all numerical values are of type float and use type hints in all your method signatures accordingly. Sorting the planets In addition your show_planets method should take a second argument, sortby, whose value is a string indicating how to sort the planets before displaying them (this is not part of the textbook description). For example, ss.show_planets(sortby = ‘distance’) displays the planets in the order of increasing distance from the sun. The default value of the sortby string parameter should be '', implying that the planets are printed without sorting (so you may get different orders based on the data structure you use for storing them). Other possible sortby parameter values are 'name', 'distance', 'mass', and 'radius' – when set, the planet names should be sorted by the appropriate attribute, e.g., if sortby is 'mass', print the planet names in order of increasing mass (no need to print the mass).
Implementation: In the solarsystem.py module, implement the SolarSystem class as described in Section 10.5. \ Your SolarSystem class should include these methods: __init__, add_planet, show_planets.
You can assume that all numerical values are of type float and use type hints in all your method signatures accordingly.
Sorting the planets
In addition your show_planets method should take a second argument, sortby, whose value is a string indicating how to sort the planets before displaying them (this is not part of the textbook description). For example, ss.show_planets(sortby = ‘distance’) displays the planets in the order of increasing distance from the sun. The default value of the sortby string parameter should be '', implying that the planets are printed without sorting (so you may get different orders based on the data structure you use for storing them). Other possible sortby parameter values are 'name', 'distance', 'mass', and 'radius' – when set, the planet names should be sorted by the appropriate attribute, e.g., if sortby is 'mass', print the planet names in order of increasing mass (no need to print the mass).
Step by step
Solved in 4 steps with 1 images