All the codes are given except for the def merge() in class Star_cluster
class Planet:
def __init__(self, a_str, a_boolean, an_int):
self.type = a_str
self.in_habitable_zone = a_boolean
self.number_of_moons = an_int
class Star:
def __init__(self, a_str, a_float, a_planet_list):
self.name = a_str
self.surface_temperature = a_float # in Kelvin
self.orbiting_planets = a_planet_list # list of Planet-objects
class Star_cluster():
def __init__(self):
self.star_list = [] # list of Star-objects
self.total_number_of_planets = 0
def add(self, star):
self.star_list.append(star)
self.total_number_of_planets += len(star.orbiting_planets)
def merge(self, a_star_cluster):
self.star_list.append(a_star_cluster)
planet1 = Planet('rocky', True, 1)
planet2 = Planet('gas giant', False, 9)
planet3 = Planet('rocky', True, 3)
star1 = Star('Alpha Centauri', 9001.0, [])
star2 = Star('Betelgeuze', 3000.0, [planet1])
star3 = Star('Tau Ceti', 7000.0, [planet2, planet3])
sc1 = Star_cluster()
sc1.add(star1)
sc2 = Star_cluster()
sc2.add(star2)
sc2.add(star3)
sc1.merge(sc2)
print "should be 3: %d" % (len(sc1.star_list))
The only thing we need to put inside this code is the def merge but I keep getting 2 instead of 3. We have an exam tomorrow but our teacher does not give us any answers....