Example #1
0
#!/usr/bin/env python3

import record_jar_reader as rjr


def print_planet_info(planet):
    print("{name} has an orbital radius of {orbital_radius}".format(
        name=planet['Planet'], orbital_radius=planet['Orbital-Radius']))


if __name__ == '__main__':
    import sys

    for planet in rjr.record_reader(sys.stdin):
        print_planet_info(planet)
Example #2
0
		self.name = planet_dict['Planet']
		self.orbital_radius = planet_dict['Orbital-Radius']
		self.diameter = planet_dict['Diameter']
		self.mass = planet_dict['Mass']
		self.moons = planet_dict['Moons'] if 'Moons' in planet_dict else None

	def __str__(self): # note 3
	   return "{name} has an orbital radius of {orbital_radius}".format(
		name=self.name, 
		orbital_radius=self.orbital_radius)


if __name__ == '__main__':
	import sys
	
	planets = [ Planet(planet) for planet in rjr.record_reader(sys.stdin) ] # note 4
	
	for planet in planets:
		print(planet) # note 5


# note 1: this how we define a class in python. We won't get to too
# many details about OOP in Python in the remaining days of class, but
# hopfully you can tell from the example that it is fairly clean and
# simple (Python was designed to be an OOP language from the ground
# up) 
#
# Notice that all member functions take the variable 'self' as their
# first argument. This is a reference the object itself, like the
# 'this' pointer in C++
Example #3
0
#!/usr/bin/env python3

import record_jar_reader as rjr

def print_planet_info(planet):
	print("{name} has an orbital radius of {orbital_radius}".format(
		name=planet['Planet'], 
		orbital_radius=planet['Orbital-Radius'])
	     )


if __name__ == '__main__':
	import sys
	
	print("A Happy List of Planets")

	for planet in rjr.record_reader(sys.stdin):
		print_planet_info(planet)