# Planets.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-22 File created. # 2022-12-27 Converted to Python 3. # In the file pythonfilesextra\PlanetsDictionary.py you can find # another version of this program which uses a dictionary for # storing Planet objects. class Planet : def __init__( self, given_planet_name, given_mean_distance_from_sun, given_circulation_time_around_sun, given_rotation_time_around_own_axis, given_equatorial_radius_in_kilometers, given_mass_compared_to_earth, given_number_of_moons ) : self.planet_name = given_planet_name self.mean_distance_from_sun = given_mean_distance_from_sun self.circulation_time_around_sun = given_circulation_time_around_sun self.rotation_time_around_own_axis = \ given_rotation_time_around_own_axis self.equatorial_radius_in_kilometers = \ given_equatorial_radius_in_kilometers self.mass_compared_to_earth = given_mass_compared_to_earth self.number_of_moons = given_number_of_moons def get_planet_name( self ) : return self.planet_name def print_planet_data( self ) : print( "\n %s orbits the sun in average distance of %.0f kilometers." %\ ( self.planet_name, ( self.mean_distance_from_sun * 149500000 )), end="" ) print( "\n It takes %f years for %s to go around the sun once." % \ ( self.circulation_time_around_sun, self.planet_name ), end="" ) print( "\n The radius of %s is %d kilometers." % \ ( self.planet_name, self.equatorial_radius_in_kilometers ) ) # The main program begins. # Much of the information given in the following table is # relative to the information concerning the Earth. E.g., # Pluto is 39.507 times further from the sun than the Earth. # The data concerning the number of moons may be old. planet_table = [] planet_table.append( Planet( "Mercury", 0.387, 0.241, 58.815, 2433, 0.05, 0 ) ) planet_table.append( Planet( "Venus", 0.723, 0.615, 224.588, 6053, 0.82, 0 ) ) planet_table.append( Planet( "Earth", 1.000, 1.000, 1.000, 6379, 1.00, 1 ) ) planet_table.append( Planet( "Mars", 1.523, 1.881, 1.029, 3386, 0.11, 2 ) ) planet_table.append( Planet( "Jupiter", 5.203, 11.861, 0.411, 71370, 317.93, 12 ) ) planet_table.append( Planet( "Saturn", 9.541, 29.457, 0.428, 60369, 95.07, 10 ) ) planet_table.append( Planet( "Uranus", 19.190, 84.001, 0.450, 24045, 14.52, 5 ) ) planet_table.append( Planet( "Neptune", 30.086, 164.784, 0.657, 22716, 17.18, 2 ) ) planet_table.append( Planet( "Pluto", 39.507, 248.35, 6.410, 5700, 0.18, 0 ) ) print( "\n This program can give you information about the" \ "\n planets in our solar system. Give a planet name: ", end="" ) planet_name_from_user = input() planet_index = 0 table_search_ready = False while table_search_ready == False : if planet_table[ planet_index ].get_planet_name().lower() \ .find( planet_name_from_user.lower() ) != -1 : planet_table[ planet_index ].print_planet_data() table_search_ready = True else : planet_index += 1 if planet_index == len( planet_table ) : print( "\n Sorry, could not find information on \"%s\"." % \ planet_name_from_user ) table_search_ready = True