Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Instructions Part 1 B: 1 . First, you will create the starting data text file. Open Notepad ( or any other plain text editor

Program InstructionsPart 1B:
1. First, you will create the starting data text file.
Open Notepad (or any other plain text editor) and add the following data to the file (exactly as shown):
1,Morrison,Marion,1313 Mockingbird Lane,Atlanta,GA
2,Jane,Mary,1640 Riverside Drive,Hill Valley,CA
3,Rubble,Barney,84 Beacon Street,Boston,MA
4,Davis,Betty,10 Stigwood Avenue,New York,NY
Save the file as IT244_U5_Data.txt.
2. Define program variables. You will read the records from this text file into a list in your program. Define a list variable to hold the data (i.e., recordsList). Define and initialize a record count variable to be used later (i.e., recordCount).
Reference: Refer back to your readings from Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 7: Lists.
3. Define a file handle and open your text data file for reading.
Hint: If you want to reference the file by its name using a relative file path like IT244_U5_Data.txt, this file must exist in the same folder with your Python source code (.py) file. Otherwise, you will need to include the full file path, such as C:/MyFolder/MySubFolder/MySubSubFolder/MyFile.txt
Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 9: Defining a Path to a File / Reading From and Writing to a File / File Handle.
4. Use a for loop to access each record in the file and append each record to the list variable each iteration.
Hint: Use strip to remove any line breaks like recordsList.append(line.strip())
Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 9: Writing and Reading a Line at a Time With a File.
5. Close the file.
Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 9: Defining a Path to a File / Reading From and Writing to a File/File Handle.
6. Append the following string of data to the list (exactly as shown):
5,Brady,Bobby,4222 Clinton Way,Los Angeles,CA
Hint: recordsList.append("5,Brady,Bobby,4222 Clinton Way,Los Angeles,CA")
7. Open a new csv file for writing. Name this file IT244_U5_PromoCredit.csv.
Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 9: Defining a Path to a File / Reading From and Writing to a File / File Handle.
8. Write a record to the file that contains the following values that will serve as the header record in your csv file:
Customer ID, Last Name, First Name, Address, City, State, Promo Credit
Hint: add
to the end of this string to force a new line.
Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 9: Defining a Path to a File / Reading From and Writing to a File / File Handle.
9. Use another for loop to process the list data.
With each iteration through the loop, write out a record.
Append the $500 promotional credit.
Hint: This can be done by simply adding the value in a string like file.write(",$500
"). Dont forget the newline character at the end.
Increment the record count variable.
10. Close the file.
11. Conclude the program by printing a statement that includes the record count:
There were 5 records written to the promo credits csv file.
Summary of files used in this program:
INPUT: IT244_U5_Data.txt
1,Morrison,Marion,1313 Mockingbird Lane,Atlanta,GA
2,Jane,Mary,1640 Riverside Drive,Hill Valley,CA
3,Rubble,Barney,84 Beacon Street,Boston,MA
4,Davis,Betty,10 Stigwood Avenue,New York,NY
OUTPUT: IT244_U5_PromoCredit.csv
(This table represents the .csv file opened in a spreadsheet application)
Customer ID
Last Name
First Name
Address
City
State
Promo Credit
1
Morrison
Marion
1313 Mockingbird Lane
Atlanta
GA
$500
2
Jane
Mary
1640 Riverside Drive
Hill Valley
CA
$500
3
Rubble
Barney
84 Beacon Street
Boston
MA
$500
4
Davis
Betty
10 Stigwood Avenue
New York
NY
$500
5
Brady
Bobby
4222 Clinton Way
Los Angeles
CA
$500

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

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions