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. PLEASE READ THE INSTRUCTIONS BEFORE CONTINUING function is defined below: def import_and_create_bank(filename):

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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.

PLEASE READ THE INSTRUCTIONS BEFORE CONTINUING

function is defined below:

def import_and_create_bank(filename):

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY