Write a solarsystem.py
file that implements the Planet
, Star
, and System
objects such that running the cells in this notebook produce the desired output. For calculating planet densities, just use that the density of Earth is 5.51 g/cc, and scale from there.
In [1]:
from solarsystem import Planet, Star, System
In [2]:
sun = Star()
print(sun)
Output should be:
Sol: 1.00 M_sun, 1.00 R_sun
In [3]:
half_sun = Star(mass=0.5, radius=0.5, name='Demisol')
print(half_sun)
Output should be:
Demisol: 0.50 M_sun, 0.50 R_sun
In [4]:
earth = Planet(365, 1.0, mass=1.0, name='Earth')
print(earth)
venus = Planet(226, 0.92, name='Venus') #if mass not provided, use M = R^2
print(venus)
venus.mass = 0.81 #Venus's actual mass
print venus.density
Output should be:
Earth: 365 days, 1.00 R_earth, 1.00 M_earth, density = 5.5 g/cc
Venus: 226 days, 0.92 R_earth, 0.85 M_earth, density = 6.0 g/cc
5.73156386126
In [5]:
ss = System(sun, planets=[earth, venus])
print ss.n_planets
mercury = Planet(88, 0.38, name='Mercury')
ss.add_planet(mercury)
print ss.n_planets
print(ss)
Output should be:
2
3
Sol: 1.00 M_sun, 1.00 R_sun
Mercury: 88 days, 0.38 R_earth, 0.14 M_earth, density = 14.5 g/cc
Venus: 226 days, 0.92 R_earth, 0.85 M_earth, density = 5.7 g/cc
Earth: 365 days, 1.00 R_earth, 1.00 M_earth, density = 5.5 g/cc
In [6]:
print(ss['Earth'])
Output should be:
Earth: 365 days, 1.00 R_earth, 1.00 M_earth, density = 5.5 g/cc
In [7]:
ss2 = System(half_sun)
ss2.add_planet(Planet(44, 0.19))
ss2.add_planet(Planet(182, 0.5))
ss2.add_planet(Planet(113, 0.46))
print(ss2)
Output should be:
Planet does not have name, will be named Demisol-b.
Planet does not have name, will be named Demisol-c.
Planet does not have name, will be named Demisol-d.
Demisol: 0.50 M_sun, 0.50 R_sun
Demisol-b: 44 days, 0.19 R_earth, 0.04 M_earth, density = 29.0 g/cc
Demisol-d: 113 days, 0.46 R_earth, 0.21 M_earth, density = 12.0 g/cc
Demisol-c: 182 days, 0.50 R_earth, 0.25 M_earth, density = 11.0 g/cc
In [ ]: