forked from AdaGold/Languages
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d505a4
commit 890a11c
Showing
1 changed file
with
34 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,51 @@ | ||
STATE_FILES = {"Washington": "povWA.txt", "South Dakota": "povSD.txt"} | ||
|
||
def print_child_poverty_info(state): | ||
def get_minimum_child_poverty_record(state): | ||
data_file = open(STATE_FILES[state], 'r') | ||
current_min = None | ||
current_max = None | ||
min_county_record = None | ||
max_county_record = None | ||
|
||
# get the values to compare against | ||
for i, record in enumerate(data_file): | ||
if i == 1: | ||
current_min = float(record[76:80]) | ||
min_county_record = record | ||
current_max = float(record[76:80]) | ||
max_county_record = record | ||
break | ||
|
||
# get max and min | ||
if i > 0: | ||
if current_min is None: | ||
current_min = float(record[76:80]) | ||
if float(record[76:80]) < current_min: | ||
current_min = float(record[76:80]) | ||
min_county_record = record | ||
|
||
data_file.close() | ||
return min_county_record | ||
|
||
|
||
def get_maximum_child_poverty_record(state): | ||
data_file = open(STATE_FILES[state], 'r') | ||
current_max = None | ||
max_county_record = None | ||
|
||
for i, record in enumerate(data_file): | ||
child_pov_percentage = float(record[76:80]) | ||
if i > 0: | ||
if current_max is None: | ||
current_max = float(record[76:80]) | ||
if float(record[76:80]) > current_max: | ||
current_max = float(record[76:80]) | ||
max_county_record = record | ||
|
||
data_file.close() | ||
return max_county_record | ||
|
||
# change minimum as needed | ||
if child_pov_percentage < current_min: | ||
current_min = child_pov_percentage | ||
min_county_record = record | ||
print get_minimum_child_poverty_record("Washington") | ||
print get_maximum_child_poverty_record("Washington") | ||
print get_minimum_child_poverty_record("South Dakota") | ||
print get_maximum_child_poverty_record("South Dakota") | ||
|
||
# change maximum as needed | ||
if child_pov_percentage > current_max: | ||
current_max = child_pov_percentage | ||
max_county_record = record | ||
|
||
def print_child_poverty_info(state): | ||
min_county_record = get_minimum_child_poverty_record(state) | ||
max_county_record = get_maximum_child_poverty_record(state) | ||
|
||
print "In {0}:".format(state) | ||
print "The county with the lowest percentage of children in poverty is {0}. In that county, {1} children ({2}%) are in poverty. The median household income is ${3}.".format(min_county_record[193:239].strip(), min_county_record[49:57].strip(), min_county_record[76:80].strip(), min_county_record[133:139].strip()) | ||
print "The county with the highest percentage of children in poverty is {0}. In that county, {1} children ({2}%) are in poverty. The median household income is ${3}.".format(max_county_record[193:239].strip(), max_county_record[49:57].strip(), max_county_record[76:80].strip(), max_county_record[133:139].strip()) | ||
|
||
data_file.close() | ||
|
||
print_child_poverty_info("Washington") | ||
print_child_poverty_info("South Dakota") |