Answered Essay: using Python 3.1

using Python 3.1

Attached Files:

File test_taxes.py (1.45 KB)

File taxes.csv (62 B)

File unit_test1.py (710 B)

File unit_test3.py (557 B)

File unit_test2.py (535 B)

Objectives:

The purpose of this homework assignment is to demonstrate your ability to apply what you have learned about format strings, modular programming and writing text files.

Instructions:

You are to create a module that I can import into my program that performs according to specification. Here’s what the module will do:

1. The first program will be named get_state_sales_tax().

this function doesn’t have any parameters, but does return a dictionary

the function reads a file named taxes.csv, attached, and splits the data into state and sales tax rate multiplier

the state serves as the key and tax rate multiplier as the value for each key-value pair in the dictionary

note that the name of the function MUST BE named get_state_sales_tax()

2. The second program will be named get_state_total(s, p, r)

The first parameter is a string and contains the name of a state

The second is a floating point value representing a price

The third is a floating point value representing a sales tax multiplier

The purpose of the function is to return a string suitable for display that includes the state, the price and the total price, including sales tax

The string should look like this

New Jersey (price / with tax): $1.95 / $2.09

where s is “New Jersey”, p is 1.95 and r is 1.07

The field width for the state must be 15 characters wide with blank fill so that the dollar signs all line up (refer to the video)

3. The third program is named log_it(m) and logs a message, m, appending it to the end of a text file.

The log file must be named tax_log.txt

The old messages must be preserved, meaning the file gets longer and longer each time log_it(m) is called.

Remember to open and close the file at the start and end of the function

Remember to append a new line to each message when writing the file

Note that all files must be in the same directory. That includes the test programs, your module and the CSV file.
Resources:

Here’s a video demonstrating how your program should behave and what the display should look like:
https://youtu.be/HBOjFmJC17g

unit_test1.py – This program tests just your taxes.get_state_sales_tax() function. Make no changes to unit_test1.py. Just run it.
unit_test2.py – This program tests just your taxes.get_state_total() function. Make no changes to unit_test2.py. Just run it.
unit_test3.py – This program tests your taxes.log_it() function. Make no changes to unit_test3.py. Just run it.

test_taxes.py – System test program. You run this program to test that all of the functions in your module work. You do not make any changes to this file. You just run it.

 

Expert Answer

 

Note: Please place the all .py and .csv files in a same folder.

1.

Program screenshot:

Sample input file screenshot:

Sample output screenshot:

Code to copy:

# import csv module

import csv

# Create a funciton named “get_state_sales_tax”.

# This function is used to read the data from the

# file named “taxes.csv” and stored in dictonary.

def get_state_sales_tax():

with open(“taxes.csv”,”r”) as data_file:

# Read and split the file to lines

lines = data_file.read().split(‘n’)

# Create a while loop to add the data in a dictonary

while ” in lines:

# The following line is used to remove the empty

# line in a data

lines.remove(”)

# Dictionary to hold the required data

sales_tax_dict = dict()

# Create a “for” loop to read each line and

# assign in a dictonary.

for each_line in lines:

state, tax_rate = each_line.split(‘,’)

sales_tax_dict[state] = float(tax_rate)

# Return dictonary

return sales_tax_dict

# The following statements are used to test the function

# named “get_state_sales_tax”.

# Call the function

data=get_state_sales_tax()

# Display the data in the dictonary.

for state, tax in data.items():

print(state, tax)

———————————————————————————

2.

Program screenshot:

Sample ouput screenshot:

Code to copy:

# Create a funciton named “get_state_total”.

# This function is used to display a string which

# contains state, price and total price including sales tax.

def get_state_total(s,p,r):

info=s[:15]+”(price / with tax): $”+str(round(p,2))+”/$”+ str(round((p*r),2))

#information = f'{s:15s}(Price/with tax):${p:.2f}/${p*r:.2f}’

return info

# The following statements are used to check

# the function named “get_state_total”.

print(get_state_total(‘New Jersey’,1.95,1.07))

—————————————————————————

3.

Program screenshot:

Sample output screenshot:

Code to copy:

# Create a function named “””.

# This funciton is used to append a message

# in tax_log.txt file.

def log_it(m):

# Open the file in append mode

with open(“tax_log.txt”,”a”) as log_data_file:

# Add a newline character to our message

m += “n”

# Write the message in a file.

log_data_file.write(m)

# Close the file

log_data_file.close();

# The following programs are used to text

# function.

log_it(“Hello how are you?”)

log_it(“This is a second message.”)

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?