CSCI 102 - Intro to Computer Science LAB

Python Assignment

Quick Links: zyBook | Piazza | Canvas | CS @ Mines

Home | Contact | Schedule | Assignments | Syllabus |

Week 10 Python Assignment
Due by Tuesday, November 9th, 2021
        Part A: Parse Depth Range (submit to Gradescope by 11:45pm)
        (No Part B)


Welcome to your assignment for Week 10 of CSCI 102! Each week, after Studio, you should work on that week's homework assignment (lab). This lab is to be done on your own (not pair programming), and needs to be completed and submitted to Gradescope no later than 11:45 PM on the due date. Unlike CSCI 101, we will place all assignments for a given week on one HTML page. This is your Week 10 CSCI 102 Assignment page.

Good news: only ONE 102 lab assignment this week.

Parse Depth Range (8 points)

Introduction

To get started, open IDLE and create a New File via the File menu. We suggest you immediately save this file in the directory managing all your 102 Python Labs this semester. Please save this file with the following name: Week10-depth_range.py.

© Mines Geology Trail

Problem Statement

When analyzing subsurface geologic formation data, often the data is presented in the following comma-delimited format:

Depth,Formation
0-600.5,Green Mountain Conglomerate
600.5-1505.65,Denver Formation

Unfortunately, this format is undesirable because it is not ideal to graph a "range" (e.g., 0-600.5) on x and y axes; one would much rather graph one number, typically the formation tops. Your task for this problem is to parse the depth ranges within the formations.csv file and add three new columns: start depth, end depth, and difference in depth. For example, if you parsed the example data given above, it would look like the following:

Depth,Start Depth,End Depth,Difference in Depth,Formation
0-600.5,0.0,600.5,600.50,Green Mountain Conglomerate
600.5-1505.65,600.5,1505.65,905.15,Denver Formation

Write a program that parses the depth ranges in the formations.csv file. You need to extract the start and end depths from the range (e.g., take the string 600.5-1505.65 and extract the floats 600.5 and 1505.65), calculate the difference in depth to 2 decimal places, and add these three new columns for each formation. Write both the original data and the three new columns of data to a new CSV file, formations_parsed.csv. Include the new header row in the new file as well.

A few notes:
  • You should save the formations.csv file in the same directory as your Python file.
  • The header of each file (the first row) should always be identical for each input file as well as identical for each output parsed file.
  • Your program should create a new file called formations_parsed.csv.
  • We encourage you to open formations_parsed.csv in a text editor (such as Notepad, NOT Excel) and make sure the contents of formations_parsed.csv match the sample output.

Lab I/O Format

There is not any user input/ouput for this lab. Your program should read in a file and create a new file without any user input.

Example Execution #1

Sample Input 1 (File formations.csv)
Depth,Formation
0-600.5,Green Mountain Conglomerate
600.5-1505.65,Denver Formation
1505.65-1805.65,Arapahoe Formation
1805.65-2410.83,Laramie Formation

Sample Output 1 (File formations_parsed.csv)
Depth,Start Depth,End Depth,Difference in Depth,Formation
0-600.5,0.0,600.5,600.50,Green Mountain Conglomerate
600.5-1505.65,600.5,1505.65,905.15,Denver Formation
1505.65-1805.65,1505.65,1805.65,300.00,Arapahoe Formation
1805.65-2410.83,1805.65,2410.83,605.18,Laramie Formation


Gradescope Submission Nuances

Part A will ONLY be submitted to Gradescope (you will NOT demo this lab in class).
When you submit your Python file to Gradescope, multiple different test cases are run on your code. Passing all of the tests results in a 100% on the autograded portion of the lab.

You are allowed to submit to Gradescope four times (or less) for this lab. The maximum grade of your submissions will be your grade for the lab. Note: If your code doesn’t work (e.g., a syntax error exists, or an error is thrown in execution), then you will receive an AUTOMATIC ZERO. You should test your code before submitting to ensure it executes correctly.

Comments

All Python files should include a header with your name, section, assignment info, references (i.e., who did you collaborate with on this assignment?; what resource did you use?), and approximate time taken to do the assignment. Be sure to cite any allowed external references used to complete the assignment. Any code without this header will lose 1 point. Here's an example:

        #  John Henke
        #  CSCI 102 – Section B
        #  Week 10 Lab
        #  References: TA Kamryn helped me read in the CSV file
        #  Time: 60 minutes

Submit Solutions

Follow these steps to submit your files to Gradescope.
  1. In Gradescope, go to CSCI 102 > Week10A and upload only Week10-depth_range.py. DO NOT submit formations.csv or formations_parsed.csv.
To receive full credit, your code must execute in Python 3, and you must submit a single file for the assignment (your Python code file).

Whenever you submit something to Gradescope, we strongly recommend you always double check what you submitted actually got submitted correctly (e.g., did the file upload correctly? did you submit the correct file? etc.) If your submission is incorrect, it's on you.