379,412 views
13 votes
13 votes
For the following code and using the help() function of the Atm_Moon class, what method(s) are inherited from Planet?

class SolarSystem:
def __init__(self, name):
self.name = 'Sun'
def show_ss_name(self):
return f'The only star in our solar system is the {self.name}'
class Planet(SolarSystem):
def __init__(self, name):
self.name = name
self.orbits_a_star = True
self.mass_enough_to_form_a_sphere = True
self.cleared_neighborhood_around_orbit = True
def show_name(self):
return f'I am planet {self.name}'
class Atm_Moon(Planet):
def __init__(self, name, atm_type, num_Moons):
super().__init__(name)
self.moons = num_Moons
self.atmosphere = atm_type
def show_moons(self):
return f'I have {self.moons} moons'
def show_atmosphere(self):
return f'My atmosphere is mostly {self.atmosphere}'
P4wAM = Atm_Moon('Mars', 'carbon dioxide',2)

A) self.moons = num_Moons
self.atmosphere = atm_type

B) __init__(self, name, atm_type, num_Moons)

C) __init__(self, name, atm_type, num_Moons)
self.moons = num_Moons
self.atmosphere = atm_type

D) show_name(self)

User Dylan Hogg
by
2.8k points

1 Answer

8 votes
8 votes

Answer:

D) show_name(self)

Step-by-step explanation:

In the given code, the Atm_Moon class is a subclass of the Planet class. This means that the Atm_Moon class inherits all the attributes and methods of the Planet class, including the show_name() method.

The show_name() method is defined in the Planet class, and it returns a string that includes the name of the planet. When called on an Atm_Moon object, this method will return a string that includes the name of the Atm_Moon object.

To confirm this, you can use the help() function to view the documentation for the Atm_Moon class. This will show you a list of all the attributes and methods that are inherited from the Planet class, including the show_name() method.

Therefore, the correct answer is option D) show_name(self).

User Pharring
by
3.1k points