Question

def clear(file_path: str): """ Clears the file at the specified file path. :param file_path: A path...

def clear(file_path: str):
    """
    Clears the file at the specified file path.
    :param file_path: A path to a file
    :return: None
    """
def delete_last_line(file_path: str) -> str:
    """
    Removes the last line in the file at the specified file path. Then it saves the new value with the last line
    removed to the file. Finally it returns the deleted last line. If the file has nothing in it an empty
    string ("") is returned.
    :param file_path: A path to file
    :return: The text in the file with the last line removed
    """
def swap_value(file_path: str, key: str, replacement):
    """
    This function will be given a file path and a key. The file that the file path points to contains a json object.
    This function should, load the data in the file. Then replace the value associated with the key with replacement
    value. Then it should overwrite the current data in the file with the new changes. Finally it should return the
    old value.

    :param file_path: A path to file
    :param key: A key value in the JSON object saved in the file
    :param replacement: The new value that the key will be mapped to
    :return: The old value that the key used to be mapped to
    """
def update_transactions(file_path: str, transaction_list: list):
    """
    You are part of a team tasked to create an application that helps bankers by saving their transactions for them.
    Your job within the project is to implement the feature that actually saves the transactions to the hard drive.
    The scope of your task is that you will be given a file path to where the data should be written and a list of
    bank transaction objects to be written to the file. The file will contain a JSON array of transactions that the
    banker previously saved. The bankers at this bank are silly sometimes and they make duplicate transactions, your
    function should remove the duplicate transactions in the transaction_list and update the existing transaction list
    saved in the file with the new transactions. Make sure when you are preforming the update of the new transactions
    that you overwrite old transactions (transactions that already exist in the file) with duplicate new transactions
    (transactions that are found in the transaction_list). You will know that a transaction is a duplicate if it has
     the same ID.

    In the end the file should contain a JSON list with transaction Objects that have been updated with the new
    information from the transaction_list. The JSON list should contain no transactions with the same ID.

    The transaction object referred to here in is outlined below. In actual testing of your code the professors
    transaction object will be used, which will have all the documented functionality.

    class Transaction:

        def __init__(self, id:int, type:str, amount:float):
            self.id:int = id
            self.type:str = type
            self.amount:float = amount

        def __str__(self):
            return 'Transaction[%s] %s $%s' (self.id, self.type, self.amount)

        def __hash__(self):
            return hash(self.id)

        def __eq__(self, other):
            return hasattr(other,'id') and other.id == self.id

    :param file_path: A path to file blank file that holds a JSON list of existing transaction and where the new
     transaction data should be written
    :param transaction_list: A list of transaction
    :return: None
    """

Homework Answers

Answer #1

File.txt:

hello.

how are you?

great,

and you?

I am great too.

dictFile:

{

   'hello':'everybody'

}

tr_list:

{

   "TransactionList": [

       {

           "id": 123456789,

           "typeOfTransaction": "check",

           "amount": 1000

       },

       {

           "id": 123423789,

           "typeOfTransaction": "withdrawals",

           "amount": 1500

       },

       {

           "id": 123457095,

           "typeOfTransaction": "check",

           "amount": 5000

       }

   ]

}

Sample output:

Last line: I am great too.

Entire file:

hello.

how are you?

great,

and you?

I am great too.

Call the write function

Write function executed

Call the write last line function

Write the last line function executed

Call clear function

File deleted

Call delete last line'

Last line deleted

Execute swap value function.

File after swapping values:

{

   "hello": "everybody"

}

old value was: every

Update transaction function

Old transaction list {'TransactionList': [{'id': 123456789, 'typeOfTransaction': 'check', 'amount': 1000}, {'id': 123423789, 'typeOfTransaction': 'withdrawals', 'amount': 1500}, {'id': 123457095, 'typeOfTransa

Transaction_list after updation: {

   "TransactionList": [

    {

      "id": 123456789,

      "typeOfTransaction": "check",

      "amount": 1000

    },

    {

      "id": 123423789,

      "typeOfTransaction": "withdrawals",

      "amount": 1500

    },

    {

      "id": 123457095,

      "typeOfTransaction": "check",

      "amount": 5000

    },

    {

      "id": 1588457096,

      "typeOfTransaction": "check",

      "amount": 20000

    }

  ]

}

Update transaction function executed

Tr_list after updation:

{

   "TransactionList": [

       {

           "id": 123456789,

           "typeOfTransaction": "check",

           "amount": 1000

       },

       {

           "id": 123423789,

           "typeOfTransaction": "withdrawals",

           "amount": 1500

       },

       {

           "id": 123457095,

           "typeOfTransaction": "check",

           "amount": 5000

       },

       {

           "id": 1588457096,

           "typeOfTransaction": "check",

           "amount": 20000

       }

   ]

}

Write_file.txt:

Hello, everybody

Step-by-step explanation

Input:

Output:

tr_list:

Output Snip:

Program Code:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies a series of transactions to the accounts. Its main() method uses the CustomerAccounts class to manage a collection of CustomerAccount objects: reading customer accounts data & transactions, and obtaining a String showing the customer accounts data after the operations are complete. You will need to complete the readCustomerAccounts () and applyTransactions() methods in the CustomerAccounts class. First, please fill in your name in the...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a room class Room(object): # the constructor def __init__(self,name,image): # rooms have a name, exits (e.g., south), exit locations (e.g., to the south is room n), # items (e.g., table), item descriptions (for each item), and grabbables (things that can # be taken and put into the inventory) self.name = name self.image = image self.exits = {} self.items = {} self.grabbables = [] # getters...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
Attention:- Your code should follow all the below instruction. Specification The file has entries like the...
Attention:- Your code should follow all the below instruction. Specification The file has entries like the following Barnstable,Barnstable,1 Bourne,Barnstable,5 Brewster,Barnstable,9 ... This code should create a dictionary where the county is the key and then total number of cases for the country is the value. The code should print the name of the county with the highest number of cases along with the total cases. The code must only use below 3 functions open_file_read cases_dictionary_create highest_cases This code must read...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT