logo Hurry, Grab up to 30% discount on the entire course
Order Now logo
970 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Lesley RobertsGeneral article writing
(5/5)

580 Answers

Hire Me
expert
Beverley RobertsonGeneral article writing
(5/5)

575 Answers

Hire Me
expert
Wyatt RyesComputer science
(5/5)

543 Answers

Hire Me
expert
Garard BerwickkCriminology
(5/5)

576 Answers

Hire Me
Python Programming
(5/5)

Each record represents a name, a price and a total number of items purchased as a single comma-separated string.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Assignment 3

Reading

Read the following sections in Introduction to Computing using Python: An Application Development Focus, Second Edition by Ljubomir Perković: 

1.    4.2 - Formatted output

2.    4.1 - Slicing

3.    4.1 - String functions

4.    4.3 - file I/O

5.                debugging (case study starting on page 471)

6.    4.4 - Exceptions

 Logistics

Please document any collaboration relevant to this assignment, in the header comment of the source file, as described in the first assignment.

 Complete the problems described below and upload your version of the solutions to the submission folder named ‘Homework 3’, in D2L.

 Assignment

Implement the functions below in the file csc401-homework3.py which can be found on the D2L site in the Week 3 folder. You should save the template file I provided and then modify that file by adding the bodies for the functions. When you do, make sure to remove the placeholder pass statements that are currently there.

 A note about the built-in tests: these should not be your only testing. I will test your code with other inputs besides those shown in the test and your code should still

work if I have used valid values. 

1.    Implement a function named print_columns(data) that takes 1 parameter:

a. data - a list contains strings, each string representing a data record

Each record represents a name, a price and a total number of items purchased as a single comma-separated string.

 The exercise is to:

a.    split the record into its 3 parts

b.    convert the data where necessary (price should be a float and number of items an integer).

c.    Trim the name field to just the first 4 characters

d.    Calculate the total for each line ( cost multiplied by items)

e.    print out the records formatted as below:

Name               Cost   Items Total

Laai

208.10

10

2081.00

Arno

381.00

9

3428.99

Sion

327.01

1

327.01

Shay

429.50

2

859.00

Rene

535.29

4

2141.16

 Name : left justified in 20 places

 

Cost : right justified in 6 places, 2 decimal places Items : right justified in 6 places

Total: right justified in 8 places, 2 decimal places

 Some fiddling with the headers, spaces between the captions may be necessary. Names should line up under “Name”, costs should line up under “Cost”, totals should line up under “Total”.

Examples:

>>> print_columns(sample_data)

Name

Cost

Items

Total

Laai

208.10

10

2081.00

Arno

381.00

9

3428.99

Sion

327.01

1

327.01

Shay

429.50

2

859.00

Rene

535.29

4

2141.16

 Notes

1.    The test data sample_data is in csc401-homework3.py already.

2.    The captions are all left justified

 3.    Write a function scan_for(file_name, word) that takes 2 string parameters:

file_name - a string representing a file name

word – a word to scan for in the file

The function reads the file and prints the number of occurrences of the specified word that exist in the file, in the format displayed below in the example output. 

The function must ignore any of these punctuation marks: . ! ?

That is, ‘cat’ and ‘cat?’ are 2 instances of ‘cat’. You are permitted to remove the punctuation from the text 

The following is sample output using a file available with the homework template: 

>>> scan_for('shoes.txt', 'I')

The word I appears 5 times in shoes.txt

>>> scan_for('shoes.txt', 'shoes')

The word shoes appears 3 times in shoes.txt

>>> scan_for('shoes.txt', 'tree')

The word tree appears 0 times in shoes.txt

(5/5)
Attachments:

Expert's Answer

970 Times Downloaded

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme