Question & Answer: You are to create a module that I can import into my program that performs according to specification. Here's what the module will d…..

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:

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

 

taxes.py

#

# Start Here

#

def get_state_sales_tax():

”’ Takes in no arguments , it reads file “taxes.csv” and returns a

dictionary having state as key and tax multiplier as value”’

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

lines = taxFile.read().split(‘n’) # Read and split the file to lines

while ” in lines: # While loop to remove any empty line from lines

lines.remove(”) # this line actually removes the empty line

sales_dict = dict() # Dictionary to hold the required data

for line in lines: # Iterating through each line

state, salesRate = line.split(‘,’) # Getting values from the line

sales_dict[state] = float(salesRate) # Populating dictionary

return sales_dict

def get_state_total(s,p,r):

”’ Takes in 3 arguments state, price and tax rate and returns a string

with calculated price after tax ”’

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

return information

def log_it(m):

”’ Takes a string as argument and logs that string to a file “tax_log.txt”

and returns nothing”’

with open(“tax_log.txt”,”a”) as logfile: # Open the file in append mode

m += “n” # add a newline character to our message

logfile.write(m) # This line actually writes data to the file

CODE:

PLEASE RATE !!

Still stressed from student homework?
Get quality assistance from academic writers!