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).

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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).

class Solar System:
def _init_(self, aSun):
self._theSun = aSun
self._planets = []
def addPlanet(self,aPlanet):
self._planets.append (aPlanet)
def showPlanets (self):
for aPlanet in self._planets:
print(aPlanet)
Transcribed Image Text:class Solar System: def _init_(self, aSun): self._theSun = aSun self._planets = [] def addPlanet(self,aPlanet): self._planets.append (aPlanet) def showPlanets (self): for aPlanet in self._planets: print(aPlanet)
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY