jeudi 23 avril 2015

Python read from file and show total max and min population from year 1900-1990

I'm working on this python code where I have to open up this file http://ift.tt/1OLHGBf and read from it so that it finds out the total population with the max and min from the years 1900 - 1990 but I cant quite figure it out I'd appreciate any help .. here is an example of how the finished code should look like http://ift.tt/1HsSiGl

def open_file():
    data = open("urpop0090.txt","r")

def STATES(check_year):
  check_year.extend(input_year2)
  data = open("urpop0090.txt","r")
  check_year.remove("UNITED STATES")
  check_year.remove("%")
  check_year.pop("%")

def check_year(year):
if year >= 1900 and year <= 1990:
      if year % 10 == 0:
#X axis horizontally on x axis
        if year == 1990 or year == 1980 or year == 1970: #1st page
            x= 0
        elif year == 1960 or year == 1950 or year == 1940:#2nd page
            x = 52
        elif year == 1930 or year == 1920 or year == 1910:#3rd page
            x = 154
        elif year == 1900:
            x = 206
#Y axis going vertically by spaces
        if year == 1990 or year == 1960 or year == 1930 or year == 1900:#1st page
            y= 1
        elif year == 1980 or year == 1950 or year == 1920:#2nd page
            y = 7
        elif year == 1970 or year == 1940 or year == 1910:#3rd page
            y = 12
        #elif year == 1900:
              #y = 241

        return (x,y)

def search(myFile, x , y):
data = open ("urpop0090.txt","r")


def print_max_min(census_list):
max = 0
max_tuple = ()
min = 99999999
min_tuple = ()

for tuple in census_list:
    if tuple[1] > max:
        max = tuple[1]
        max_tuple = tuple
    elif tuple[1] < min:
        min = tuple[1]
        min_tuple = tuple

print ("the maximum is : ({} {:>,d)".format(max_tuple[0],max_tuple[1]),
       "\nthe minimum is : ({} {:>,d})".format(min_tuple[0], min_tuple[1]))

import string, sys

while True:
myFile = open_file()

try:
    year = input("Enter a census year 1900 - 1990 (must end with 0): ")
    year = int(year)
except ValueError:
    print("Non-Integer value input:", year)
    print("")
    continue

page_num, block_num = check_year(year)
if page_num != "Error":
    census_list = search (myFile, page_num, block_num)
    print_max_min(census_list)

myFile.close()

Aucun commentaire:

Enregistrer un commentaire