Your professor asked your TA to collect student information and store it in a file called studentInfo.txt, but this TA spilled Pepsi on the keyboard while entering the data. As a result, there are extra or missing spaces and missing commas throughout the file. For example, the file has wd50,WillDavidson, 090,3 hpj4332, Helen Jordan1983.88 xd222XavierDavies1983.65 ad12 AdDavies1983.65 Suppose the file contains netID, name, major, and GPA in that order. Can you help this TA make the file more readable? To accomplish this task, you may assume the following about each field: netID: begins with 2-3 lowercase letters followed by 1-4 digits (e.g., wd1, wxo001, tsy1234) name: contains both first name and last name with their first letter capitalized (e.g., "John Doe", "MarySmith"). There may be zero or more spaces between the first name and last name. major: 3-digit code (e.g., 198) GPA: floating point number between 0.0 and 4.0 (inclusive). There may or may not be a decimal point (e.g., 3.0 or 3). Write a function called reformat_student_info to convert a file into a standard format, which has exactly one comma followed by one space to separate each field. The function should accept a filename string parameter. Write the cleaned data to a new file called studentInfoReformatted.csv and format the file as follows: netID, name, major, GPA There should be exactly one comma followed by one space to separate each field. The name field should include exactly one space between first name and last name, and the GPA should have a decimal even if the GPA from the input file does not (e.g., 3.0 instead of 3). The reformatted file for the sample above should look like this: wd50, Will Davidson, 090, 3.0 hpj4332, Helen Jordan, 198, 3.88 xd222, Xavier Davies, 198, 3.65 ad12, Ad Davies, 198, 3.65 def reformat_student_info(filename): # YOUR CODE HERE raise NotImplementedError()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Your professor asked your TA to collect student information and store it in a file called studentInfo.txt, but this TA spilled Pepsi on the keyboard while entering the data. As a result, there are extra or missing spaces and missing commas throughout the file. For example, the file has

wd50,WillDavidson, 090,3 hpj4332, Helen Jordan1983.88 xd222XavierDavies1983.65 ad12 AdDavies1983.65

Suppose the file contains netID, name, major, and GPA in that order. Can you help this TA make the file more readable?

To accomplish this task, you may assume the following about each field: netID: begins with 2-3 lowercase letters followed by 1-4 digits (e.g., wd1, wxo001, tsy1234) name: contains both first name and last name with their first letter capitalized (e.g., "John Doe", "MarySmith"). There may be zero or more spaces between the first name and last name. major: 3-digit code (e.g., 198) GPA: floating point number between 0.0 and 4.0 (inclusive). There may or may not be a decimal point (e.g., 3.0 or 3).

Write a function called reformat_student_info to convert a file into a standard format, which has exactly one comma followed by one space to separate each field. The function should accept a filename string parameter. Write the cleaned data to a new file called studentInfoReformatted.csv and format the file as follows:

netID, name, major, GPA

There should be exactly one comma followed by one space to separate each field. The name field should include exactly one space between first name and last name, and the GPA should have a decimal even if the GPA from the input file does not (e.g., 3.0 instead of 3).

The reformatted file for the sample above should look like this:

wd50, Will Davidson, 090, 3.0 hpj4332, Helen Jordan, 198, 3.88 xd222, Xavier Davies, 198, 3.65 ad12, Ad Davies, 198, 3.65

def reformat_student_info(filename):

# YOUR CODE HERE
raise NotImplementedError()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education