Introduction to Python Programming Programming Assignment: Homework 4 – Online Banking System Answer

SOLUTIONS LINK :- https://youtu.be/BQ4zpoLPa4Q

Module 4
In this assignment, you will implement an online banking system. Users can sign-up with the system, log in to the system, change their password, and delete their account. They can also update their bank account balance and transfer money to another user’s bank account.

You’ll implement functions related to File I/O and dictionaries. Two of the functions require you to import files and create dictionaries. User information will be imported from the “users.txt” file and account information will be imported from the “bank.txt” file. Take a look at the content in the different files. The remaining functions require you to use or modify the two dictionaries created from the files.

Each function has been defined for you, but without the code. See the docstring in each function for instructions on what the function is supposed to do and how to write the code. It should be clear enough. In some cases, we have provided hints to help you get started.

###########################################################
### EXECUTE THIS CELL BEFORE YOU TO TEST YOUR SOLUTIONS ###
###########################################################

import nose.tools as tools

lst=data.read
def import_and_create_bank(filename):
”’
This function is used to create a bank dictionary. The given argument is the filename to load.
Every line in the file should be in the following format:
key: value
The key is a user’s name and the value is an amount to update the user’s bank account with. The value should be a
number, however, it is possible that there is no value or that the value is an invalid number.

What you will do:
– Create an empty bank dictionary.
– Read in the file.
– Add keys and values to the dictionary from the contents of the file.
– If the key doesn’t exist in the dictionary, create a new key:value pair.
– If the key does exist in the dictionary, increment its value with the amount.
– You should also handle the following cases:
— When the value is missing or invalid. If so, ignore that line and don’t update the dictionary.
— When the line is completely blank. Again, ignore that line and don’t update the dictionary.
— When there is whitespace at the beginning or end of a line and/or between the name and value on a line. You
should trim any and all whitespace.
– Return the bank dictionary from this function.

For example, here’s how your code should handle some specific lines in the file:
The 1st line in the file has a name and valid number:
Brandon: 5
Your code will process this line and add the extracted information to the dictionary. After it does,
the dictionary will look like this:
bank = {“Brandon”: 5}

The 2nd line in the file also has a name and valid number:
Patrick: 18.9
Your code will also process this line and add the extracted information to the dictionary. After it does,
the dictionary will look like this:
bank = {“Brandon”: 5, “Patrick”: 18.9}

The 3rd line in the file has a name but invalid number:
Brandon: xyz
Your code will ignore this line and add nothing to the dictionary. It will still look like this:
bank = {“Brandon”: 5, “Patrick”: 18.9}

The 4th line in the file has a name but missing number:
Jack:
Your code will ignore this line and add nothing to the dictionary. It will still look like this:
bank = {“Brandon”: 5, “Patrick”: 18.9}

The 5th line in the file is completely blank.
Your code will ignore this line and add nothing to the dictionary. It will still look like this:
bank = {“Brandon”: 5, “Patrick”: 18.9}

The 8th line in the file has a name and valid number, but with extra whitespace:
Brandon: 10
Your code will process this line and update the value associated with the existing key (‘Brandon’) in the dictionary.
After it does, the value associated with the key ‘Brandon’ will be 10:
bank = {“Brandon”: 15, …}

After processing every line in the file, the dictionary will look like this:
bank = {“Brandon”: 115.5, “Patrick”: 18.9, “Sarah”: 827.43, “Jack”: 45.0, “James”: 128.87}
Return the dictionary from this function.

Leave a Reply

Your email address will not be published. Required fields are marked *