University of Maryland Baltimore County Create a Program Code Python Coding Task
Description
This program relies on a series of data files. Simply right-click on the links below (control-click on a Mac) and select Save-As to save these files to your computer. Ensure that these files are stored in a folder that contains your source code file
username: snp379
password: Manu1022
class_data.txt
Stores the course ID and the title of each course. There will always be one record in this file for every course that the CS department is currently offering. Here’s what this file looks like:
CS0002,Introduction to Computer Programming
CS0004,Introduction to Web Design and Computer Principles
CS0060,Database Design and Implementation
CS0061,Web Development
CS0101,Introduction to Computer Science
CS0102,Data Structures
CS0201,Computer Systems Organization
CS0380,Special Topics in Computer Science
enrollment_data.txt
Stores the course ID, last name and first name of each student enrolled in the course. Note that there are multiple records per course (one per student enrolled). For example, here’s the beginning of this file showing six students enrolled in CS0002:
CS0002,Hiner,Judith
CS0002,Mcmahon,Ludivina
CS0002,Trusty,Beatrice
CS0002,Brinn,Jacqulyn
CS0002,Hintzen,Floria
CS0002,Amyx,Randolph
Your task is to write a program that asks the user for a course ID. The program will then determine if the course ID is valid or not — if it is not, the program can safely end. If it is valid, the program should report the full title of the course, how many students are enrolled in the course and the names of each student enrolled.
You cannot hard code your program to only work with the values contained within these files. When we test your work we will be using completely different data files that are organized in the same way as these sample files. Your program should work flawlessly using this new data.
I’ve broken up this program into smaller tasks that you should attempt one at a time as a group. Do these in order.
Task #1
- Begin by asking the user for a course.
- Next, open the file
class_data.txt
for reading and obtain all data from the file. - You’ll need to parse this file so you can access the data you care about. Take a look at how the file is being organized:COURSE_NUMBER_1,COURSE_DESCRIPTION_1 COURSE_NUMBER_2,COURSE_DESCRIPTION_2 COURSE_NUMBER_2,COURSE_DESCRIPTION_2
- Each line contains information about a course. On each line you have two values to work with – the course number and the course description. These values are separated by commas.
- The first step is to isolate the individual lines from one another.
- Hint: the
split
method may be useful here! - After this, you need to examine each line and identify if that line contains the course number that the user typed in. This will require you to isolate the course number from the course description.
- Hint: a
for
loop along with another call to thesplit
method may be useful here! - Store the title somewhere (an accumulator variable?) so you can access it later.
- Finally, generate some output to let the user know if (a) the course cannot be found or (b) the course can be found, along with the title. Do this outside of the loop that you used to find the course. Hint: you may need to set a variable to indicate that you found the course, along with the course title to do this.
At the end of task #1 your program should operate as follows:
Enter a course: pikachu
That course is not running this semester
Enter a course: CS
That course is not running this semester
Enter a course: CS0002
The title of this class is: Introduction to Computer Programming
Task #2
Next you will need to see how many students are enrolled in the course (if it exists). Here’s how to get started:
- If the course is running you will need to open up the
enrollment_data.txt
file and read in the contents of this file as a string. - This file is organized as follows:COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME
- Each line contains information about a student. On each line you have three values to work with – the course number, the last name of the student and the first name of the student. These are all separated by commas.
- Begin by isolating the individual records from one another (the lines). Then examine each line to see if that line contains a student enrolled in the desired course.
- When examining a line of data you will need to further process that line it (to extract the course number and the student name)
- If that line contains the course number in question you should make a note of it. Hint: an accumulator list may be useful to store all of the students enrolled in this course.
- Finally, after you’ve finished examining each line you should print out your final report (how many students are enrolled and each of their names)
At the end of task #2 your program should operate as follows:
NYU Computer Science Registration System
Enter a course ID (i.e. CS0002, CS0004): PIKACHU
Cannot find this course
NYU Computer Science Registration System
Enter a course ID (i.e. CS0002, CS0004): CS
Cannot find this course
NYU Computer Science Registration System
Enter a course ID (i.e. CS0002, CS0004): CS0002
The title of this class is: Introduction to Computer Programming
The course has 6 students enrolled
* Hiner,Judith
* Mcmahon,Ludivina
* Trusty,Beatrice
* Brinn,Jacqulyn
* Hintzen,Floria
* Amyx,Randolph
NYU Computer Science Registration System
Enter a course ID (i.e. CS0002, CS0004): CS0004
The title of this class is: Introduction to Web Design and Computer Principles
The course has 7 students enrolled
* Woodman,Tilda
* Schneiderman,Saran
* Conn,Glayds
* Cales,Edgar
* Hiner,Judith
* Lukens,Refugio
* Alfrey,Jerrica
NYU Computer Science Registration System
Enter a course ID (i.e. CS0002, CS0004): CS0201
The title of this class is: Computer Systems Organization
The course has 0 students enrolled
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."