1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Elina [12.6K]
3 years ago
14

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. The first two 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.
def import_and_create_dictionary(filename):
'''
This function is used to create a bank dictionary. The given argument is the filename to load.
Every line in the file will look like
key: value
Key is a user's name and 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:
- Try to make a dictionary from the contents of the file.
- If the key doesn't exist, create a new key:value pair.
- If the key does exist, increment its value with the amount.
- You should also handle cases when the value is invalid. If so, ignore that line and don't update the dictionary.
- Finally, return the dictionary.
Note: All of the users in the bank file are in the user account file.
'''
d = {}
# your code here
return d
##########################
### TEST YOUR SOLUTION ###
##########################
bank = import_and_create_dictionary("bank.txt")
tools.assert_false(len(bank) == 0)
tools.assert_almost_equal(115.5, bank.get("Brandon"))
tools.assert_almost_equal(128.87, bank.get("James"))
tools.assert_is_none(bank.get("Joel"))
tools.assert_is_none(bank.get("Luke"))
tools.assert_almost_equal(bank.get("Sarah"), 827.43)
#user.txt
Brandon - brandon123ABC
Jack
Jack - jac123
Jack - jack123POU
Patrick - patrick5678
Brandon - brandon123ABCD
James - 100jamesABD
Sarah - sd896ssfJJH
Jennie - sadsaca
#bank.txt
Brandon: 5
Patrick: 18.9
Brandon: xyz
Jack:
Sarah: 825
Jack : 45
Brandon: 10
James: 3.25
James: 125.62
Sarah: 2.43
Brandon: 100.5
Computers and Technology
1 answer:
Natalka [10]3 years ago
6 0

Answer:

# global variable for logged in users

loggedin = []

# create the user account list as a dictionary called "bank".

def import_and_create_dictionary(filename):

   bank = {}

   i = 1

   with open(filename, "r") as file:

       for line in file:

           (name, amt) = line.rstrip('\n').split(":")

           bank[i] = [name.strip(), amt]

           i += 1

   return bank

#create the list of user login details.

def import_and_create_accounts(filename):

   acc = []

   with open(filename, "r") as file:

       for line in file:

           (login, password) = line.rstrip('\n').split("-")

           acc.append([login.strip(), password.strip()])

   return acc

# function to login users that are yet to login.

def signin(accounts, login, password):

   flag="true"

   for lst in accounts:

       if(lst[0]==login and lst[1] == password):

           for log in loggedin:

               if(log ==login):

                    print("You are already logged in")

                    flag="false"

           break                    

       else:

           flag="false"  

   if(flag=="true"):

       loggedin.append(login) # adding user to loggedin list

       print("logged in succesfully")

       return True

   return False

# calling both the function to create bank dictionary and user_account list        

bank  = import_and_create_dictionary("bank.txt")            

print (bank)

user_account = import_and_create_accounts("user.txt")

print(user_account)

# check for users loggedin

signin(user_account,"Brandon","123abcAB")

signin(user_account,"James","100jamesABD")

signin(user_account,"Sarah","sd896ssfJJH")

Explanation:

The python program is a banking application system that creates a list of user accounts and their login details from the bank.txt and user.txt file. The program also uses the information to log in and check for users already logged into their account with the "loggedin" global variable.

You might be interested in
Crop marks are used on an illustration to indicate to the printer the
Advocard [28]
Crop marks are used on an illustration to indicate to the printer the A. center point of the illustration. Hope this helped!.
5 0
3 years ago
Define computer memory and write it's type ​
DochEvi [55]

Answer:

Computer memory is a generic term for all of the different types of data storage technology that a computer may use, including RAM, ROM, and flash memory. Some types of computer memory are designed to be very fast, meaning that the central processing unit (CPU) can access data stored there very quickly.

8 0
3 years ago
Look at the following HTML form. Which description is correct? Please enter your discount code:
jasenka [17]

Answer:

<form action = "discount.php" method = "post" > discount method can be extract from POST method

Explanation:

<form action = "discount.php" method = "post" >

<input type = "text" size = "12" name = "code" >

<input type = "submit" value = "Process" >

</form>

6 0
3 years ago
On Study Island, What do I do when the numbers don't show up?
mafiozo [28]
Try restarting your laptop
8 0
3 years ago
Read 2 more answers
Katarina is deciding whether to buy a desktop or a laptop computer. What will most likely help Katarina make her decision?
Gnesinka [82]
Laptops are portable decides , while desktops remain in one plcae
4 0
3 years ago
Read 2 more answers
Other questions:
  • Thomas is using a drawing program to complete a construction. Which construction could he be completing? (5 points).
    5·2 answers
  • What is one advantage of top-down programming design?
    13·2 answers
  • For example, one might start with a population of 500 organisms, a growth rate of 2, and a growth period to achieve this rate of
    6·1 answer
  • What effect does screen resolution have on how graphics are displayed?
    7·1 answer
  • Which of the following statements are valid in Java? (Assume that console is Scanner object initialized to the standard input de
    15·1 answer
  • When reading words with a scanner object, a word is defined as ____?
    15·1 answer
  • How many of yall are willing too sub to my channel called "Space Juice" with around 200 subs?!​
    6·1 answer
  • Sierra needs to ensure that when users are entering data into a datasheet or form that they are limited in the values they can s
    15·2 answers
  • Which tabs are expandable and collapsible
    14·1 answer
  • your organization has decided to use dhcp for ipv6. you want all windows 10 systems using ipv6 to get all of their tcp/ip inform
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!