Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2 - Student Loans - please use Python to solve the following question. Youll need to open and read the file twice for this

Problem 2 - Student Loans - please use Python to solve the following question.

Youll need to open and read the file twice for this problem.

Lists are not permitted in this homework

And youll process the file using while loops.

This problem has basically the same data about student loans that HW2 had

Except more of it, and now were more interested in the debt-to-tuition ratio.

The file has:

1. School name

2. Average debt per student (federal loans)

3. Yearly tuition

Open the file and read in all the data

so that you can compute the average debt for each school as a fraction of total tuition.

You can assume that a given students total tuition is the yearly tuition x4.

For example, northeasterns debt is $24,500 and tuition is $57,592

So our fraction would be 24500/(57592 x 4) = .106.

Determine the average debt to tuition fraction over all schools in the file,

So that you can later plot each individual schools fraction against this average.

Now that you have the average, youll need to open the file a second time

And read in all the data again, this time plotting it against the average.

Compute the same debt-to-tuition fraction for each school,

And plot in one color if its above the average

And a different color if its at or below average.

Create a scatterplot with tuition on the x axis, and debt fraction on the y axis.

For full credit under communication, your plot must have:

1. A title

2. Labels on the x and y axes

3. Reasonable x-limit and y-limit

4. A horizontal line showing the average debt fraction, correctly labeled

Please follow all the rubrics below!!!

Gather data

Open the file and read in school name (string), average debt (int), tuition (int), for every school using a while loop. The first time is to compute the average debt-to-tuition fraction for the schools listed in the .txt file.

Open the file a second time and read in all the same data. This time is to plot tuition vs. debt-to-tuition.

Computations

Compute total tuition to be yearly tuition x4

Compute debt-to-tuition for each school

Compute average debt-to-tuition over all schools

Lists are not used; everything is done with while loops

Communication

Use matplotlib to create a plot as described

Scatterplot with debt-to-tuition on y axis, tuition on x axis

Plot also has a horizontal line for average debt-to-tuition

Plot has labels, title, reasonable xlim/ylim, and two colors (to indicate above/below average)

Readability

File name is saved in a constant above main

image text in transcribed

image text in transcribed

Problem 2 - Student Loans Filename: loansv2.py Also submit: A screenshot (or download) of your plot Input files: Download debt vs tuition2.txt, and save it in the same directory as your loansv 2 .py file You'll need to open and read the file twice for this problem. Lists are not permitted in this homework, and you'll process the file using while loops. This problem has basically the same data about student loans that HW2 had, except more of it, and now we're more interested in the debt-to-tuition ratio. The file has: - School name - Average debt per student (federal loans) - Yearly tuition Open the file and read in all the data so that you can compute the average debt for each school as a fraction of total tuition. You can assume that a given student's total tuition is the yearly tuition x4. (For example, northeastern's debt is $24,500 and tuition is $57,592, so our fraction would be 24500/(57592x 4)=.106.) Determine the average debt to tuition fraction over all schools in the file, so that you can later plot each individual school's fraction against this average. Now that you have the average, you'll need to open the file a second time, and read in all the data again, this time plotting it against the average. Compute the same debt-to-tuition fraction for each school, and plot in one color if it's above the average, and a different color if it's at or below average. Create a scatterplot with tuition on the x axis, and debt fraction on the y axis. For full credit under communication, your plot must have: - A title - Labels on the x and y axes - Reasonable x-limit and y-limit - A horizontal line showing the average debt fraction, correctly labeled Northeastern 2450057592Tufts1975063000Brown2231662304BU2671659816BC1926861706Dartmouth2112060870Harvard2391255587HarveyMudd2457260703Amherst2096461150Williams1609859660

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

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions