- Details
- Parent Category: Programming Assignments' Solutions
We Helped With This Python Programming Homework: Have A Similar One?

Category | Programming |
---|---|
Subject | Python |
Difficulty | Undergraduate |
Status | Solved |
More Info | Python Coding Help |
Short Assignment Requirements
Assignment Description
HIMT 345
Homework 12: Application 1
Overview:
Use the skills and strategies learned in Modules 1-10 to create Python mini-programs to analyze healthcare data.
Prior Task Completion:
You should have already downloaded the complete Severance source files for Chapters 3-10. There is a screen cast video to guide that download and installation. It is found in D2L | Content | Textbook Materials and Links and looks like this:
Specifics:
Download and unzip the PyCharm Python project entitled Hwk12_STARTER.zip. After loading it into PyCharm, Refactor | Rename it to the usual <Hwk12_YourLastname>.
Three Python files are there and need renaming: from Hwk12a_STARTER to Hwk12a_YourLastname.py, etc. Several data files are also present: Patients.txt, Diagnoses.txt, Labs.txt, and Admissions.txt.
Please note that each data file has a columns descriptor line as the first line of the file. When processing, we must IGNORE that line as it is obviously not valid data. The following code preceding the actual loop that reads the file does just that. Each time you read a file containing that header line you must include this code.
fhand = open('Diagnoses.txt') # open the file, establish the file handle fhand.readline() # read the first line and ignore it
# declare and set any initialization variables here, such as counters, lists, dictionaries
for line in fhand: # loop through the file line by line
1. Hwk12a: What patient (by ID) has the most admissions?
Open Hwk12a_STARTER.py, rename it, and run it. It should display the ID field from all the lines in the file Admissions.txt. Comments included therein guide your code development.
Run and study the code in Ch 9 code sample 13. It provides most of what you need for this task.
2. Hwk12b: What are the 10 patients (by ID) having the most labs?
To tackle this task, repeat the code you wrote in 12a to create a dictionary containing IDs and the count of those IDs, this time on the Labs.txt file.
Then employ the strategies used in Ch 10 code sample 10 (ten most common words) to create a list of tuples, sort the list, and then print the first ten.
3. Hwk12c: Of the top 10 patients with the most labs, how many are male? Print their IDs, and print the number of males in the top 10.
Repeat the code you wrote in 12b to create a dictionary containing IDs and the count of those IDs, create the list, and sort the list in reverse.
Now you have to find out which of the top 10 in the list of most Labs are male. To do that, you have to loop through the Patients.txt file, checking to see if the ID is present in the same line as the word ‘Male’.
Follow the comments in the code to add the statements necessary to achieve the tasks. Don’t be afraid to add print statements to help you write the code; remove them when you’re finished. The output is shown below.
What to hand in:
Create a Word doc (Hwk12_YourLastName.doc)containing both the Python code and the console output for each of 12a, 12b, and 12c.
1. Screen snips of the code editor for 12a. Then, a screen snip of the console window showing the result 12a.
2. Similarly for each of 12b and 12c.
<CONTINUED>
3. Upload the Word doc and the Python program files for 12a, 12b, and 12c to the appropriate D2L dropbox. Four files total.
Assignment Code
# Hwk12a - What Patient (by ID) has the most admissions?
# Add the usual file documentation
fhand = open('Admissions.txt') # open the file, establish the file handle
fhand.readline() # read the first line and ignore it
for line in fhand:
# print line
# slice the line (string) to get the ID
ID = line[:8]
print ID # remove this after you get the counting down
# use the counting strategies with a dictionary shown in Chap 9 Sample 13 Find the word count fo a file
fhand.close()
# print out the result
Assignment Code
# Hwk12b - What are the top 10 patients (by ID) with the most labs?
# Add the usual file documentation
# Repeat the code you wrote in 12a to create a dictionary containing IDs and the count of those IDs.
# Use the strategies used in Ch 10 code sample 10 (ten most common words) to create a list of tuples,
# sort the list in reverse, and then print the first ten.
Assignment Code
# Hwk12c - Of the 10 patients (by ID) with the most labs, how many are male?
# Add the usual file documentation
# *** Repeat the code you wrote in 12b to create a dictionary containing IDs and the count of those IDs.
# *** Again, use the strategies used in Ch 10 code sample 10 (ten most common words) to create a list of tuples,
# sort the list in reverse, and then print the first ten.
# Given the listOfTuples, process the first ten
count = 0
for val, key in listOfTuples[:10] :
print key, val # remove this once you get going
# now must check if the key (ID) and 'Male' are in the same line of the Patients.txt file
# *** open the file 'Patients.txt' and read the first line
for line in fhand:
# *** add an if-statement to check if the ID (which is in the key position)
# is in the line, AND 'Male' is in the line
# print line # just to show that we've selected it; delete this later
# count this line - it contains both the ID and 'Male'
count = count + 1
print "Of the 10 patients with the most labs, there were " + str(count) + " males."