Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON PROGRAMMING. This assignment focuses on the design, implementation and testing of Python programs to process data files, as described below. Assignment Specifications 1. The

PYTHON PROGRAMMING.

This assignment focuses on the design, implementation and testing of Python programs to process data files, as described below.

Assignment Specifications

1. The World Health Organization (WHO) compiles data about immunization levels around the world. The file namedmeasles.txt contains data about the level of measles vaccinations in various countries over time.

measles.txt

Each line of the file contains the following fields, where there is one space between fields:

Country (50 characters)

Income Level (6 characters)

Percent Vaccinated (3 characters)

Region (25 characters)

Year (4 characters)

The Country field contains the name of the country.

The Income Level field identifies the category assigned to that country by the World Bank:

WB_LI low income

WB_LMI lower middle income

WB_UMI upper middle income

WB_HI high income

The Percent Vaccinated field contains an integer number representing the percentage of children in that country who have received measles vaccine by the age of one.

The Region field identifies the region assigned to that country by WHO.

The Year field contains the year for which the data was compiled.

Part A

1. The program in lastname_firstname_7a.pywill copy selected lines from measles.txt into a file selected by the user.

a) The program will always read from measles.txt (it will not prompt the user for the name of the input file). If it is unable to open that file, the program will halt.

b) The program will prompt the user for the name of the output file. If that file does not exist, the program will create it and continue. If that file does exist, the program will discard the current contents of the file and continue.

c) The program will prompt the user to enter a year, and will copy all lines of measles.txt selected by the users response. A line is selected if the users response matches the Year field or any of its prefixes. All lines are selected if the users response is any of the values in the set {, all, ALL}. Note that is the empty string.

For example, a line whose Year field contains 1987 would be selected by any of the following user responses: {1, 19, 198, 1987, , all, ALL}.

2. The output file created by the program will have the same format as the input file (same field widths and spacing). Note that when the user selects all lines, the output file will be identical to the input file.

3. The program will display appropriate messages to inform the user about any unusual circumstances.

Here is a part of the .txt file.

Algeria WB_UMI 88 Africa 2008

Algeria WB_UMI 92 Africa 2009

Algeria WB_UMI 95 Africa 2010

Algeria WB_UMI 95 Africa 2011

Algeria WB_UMI 95 Africa 2012

Andorra WB_HI 90 Europe 1997

Andorra WB_HI 90 Europe 1998

Andorra WB_HI 97 Europe 1999

Andorra WB_HI 97 Europe 2000

Andorra WB_HI 97 Europe 2001

Andorra WB_HI 98 Europe 2002

Andorra WB_HI 96 Europe 2003

Andorra WB_HI 98 Europe 2004

Andorra WB_HI 94 Europe 2005

Andorra WB_HI 91 Europe 2006

Andorra WB_HI 94 Europe 2007

Andorra WB_HI 98 Europe 2008

Assignment Notes

1. The data in measles.txt is from the World Health Organizations website and is used with permission:

http://apps.who.int/gho/data/node.main.A824?lang=en (Links to an external site.)Links to an external site.

2. Documentation about the built-in function open is on the Python website:

http://docs.python.org/3/library/functions.html#open (Links to an external site.)Links to an external site.

In particular, the information about modes r, w and x may be useful.

3. A simple approach to determining the maximal value in a set of values is described below.

Initialize the current maximal value to something smaller than all valid values

For each value in the set:

If the value is larger than the current maximal value, save it as the current maximal value

A similar procedure can be used to determine the minimal value in a set of values.

4. When performing file I/O its very inefficient to constantly open and close the files youre working with. Try to avoid putting the open and close in loops unless you cant figure any other way to do it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

7-16 Compare Web 2.0 and Web 3.0.

Answered: 1 week ago