You may use this script as a starting point for your Homework 5 solution.
#!/usr/bin/env python
"""Homework for CS 368-2 (2012 Spring)
Assigned on Day 05, 2012-03-27
Written by <Your Name>
"""
countries = {}
def read_country_file(filename):
country_file = open(filename, 'r')
for country_line in country_file:
(code, short, long, region) = country_line.strip().split(' : ')
countries[code] = {'short': short, 'long': long, 'region': region, 'pop': {}}
country_file.close()
def read_population_file(filename):
pop_file = open(filename, 'r')
for pop_line in pop_file:
(code, year, population) = pop_line.strip().split(' : ')
if countries.has_key(code):
countries[code]['pop'][int(year)] = int(population)
pop_file.close()
def short_name(code):
pass # replace this line with your real function
def population(code, year):
pass # replace this line with your real function
def world_population(year):
pass # replace this line with your real function
# ----------------------------------------------------------------------
# "Main" program starts below
# ----------------------------------------------------------------------
read_country_file('input-05-country.txt')
read_population_file('input-05-population.txt')
while True:
# Get and validate user input
# Stop looping if country code is empty string
# Get country and world populations for given year
# Print report