Introduction:
I just came into contact with python recently. I have learned some VB language before. It may be relatively fast to get started. I have a certain foundation for computers and a good understanding of basic algorithm ideas. Time to write this program to realize the various operations of the ATM computer, and split it into the following basic modules:
1. Log in to the system
2. Register account system
3. Deposit and withdrawal operations
4. Inquiry balance system
5. Exit the system
General idea:
It is probably split into various modules, and then each module defines a function, and finally summarizes.
Problems encountered in the process:
1. The first-generation program that has just been completed has no registration function, nor does it have the function of storing user information
Solution: Later, I consulted Daxie’s blog and learned to introduce the json module, and create a new json module to save and store user data, so that the next time I enter the program, the data can also be inherited.
2. During the test, it was found that there is always a BUG error after entering the ID repeatedly during registration, which may be a logical problem
Solution: After introducing several variables and connecting the While loop to achieve ID repetition, the system will give a prompt: re-enter and return to the previous step of entering the ID (it has been a long time of trial and error...)
3. It is also a logical problem, a small BUG, the password when registering should be 6 digits, and I forgot to limit it. Later, the introduction of the two variables True and False solved this BUG. I don’t know if there is a better solution. I hope the boss will give me pointers.
''' bank ATM program ''' import json with open('save.json', 'r') as f: bankuser = json.load(f) def save(person): # To save json, the read format should be written as 'w', and the content of the file can be changed. # Here the user data is stored in the file save.json with open('save.json', 'w') as f: json.dump(person, f) # Write this person's data, make an update # create user def create(): newuser = {} newuser['user'] = input("hint:please enter your name:") x=True # Introduce a Boolean variable of x to determine whether the ID has been registered z=True # Introduce a z variable to judge whether the next step can be performed while z is True: x=True for user in bankuser: if user['user'] == newuser['user']: print("hint:The account has been registered") x=False if x==True: # If x does not change TF, it means that the ID has not been registered, so just break out of the While loop break else:newuser['user'] = input("hint:Please re-enter your name:") # If x=False, it means that the ID has been registered, enter the ID again, and then return to the previous step to compare whether it is repeated while x is True: # If x is True then pre-store and password settings y=True # Introduce a y variable to determine whether the bank password is 6 digits newuser['bank_balance'] = int(input("hint:Please enter your deposit amount:")) newuser['password'] = input("hint:Please enter your six-digit bank password:") while y is True: if len(newuser['password'])!= 6: # If the bank password is not six, then give a prompt and re-enter the password. newuser['password'] = input("hint:Please enter your six-digit bank password (six digits!!!):") else: # If it is six, exit this loop y=False bankuser.append(newuser) # Add the data of this new user to the database save(bankuser) # save x=False # End this loop and exit the module def login_user_system(): #define a login system user_id=input("Please enter your account number:") user_password=input("Please enter your 6-digit password:") i=-1 # Database encoding starts from 0 for user in bankuser: i+=1 # Initially set to 0, indicating the first item of data if user["user"]==user_id and user["password"]==user_password: print("dear{}{},Hello, you have successfully logged in, welcome to Mihayou Bank! Please do the following!".format("vip user",user["user"])) print("-"*50) return i # Which user is given (the number of data) else: print("The password you entered is wrong, please re-enter!") def search_money(): """Define a function to query deposits""" print("Your account also has{}Yuan".format(bankuser[NewUser]["bank_balance"])) def add_money(): """Define a deposit function""" add=int(input("Please enter the amount you want to deposit:")) bankuser[NewUser]["bank_balance"]+=add print("successful deposit{}Yuan, account existing{}Yuan!".format(add,bankuser[NewUser]["bank_balance"])) def take_money(): """Define a withdrawal function""" take=int(input("Please enter the amount you want to withdraw:")) if take<=bankuser[NewUser]["bank_balance"]: bankuser[NewUser]["bank_balance"]-=take print("successful withdrawal{}Yuan, account existing{}Yuan!".format(take, bankuser[NewUser]["bank_balance"])) else: print("Your account balance is insufficient! Please re-enter the withdrawal balance!") def login_out(): """Define a function to exit the system""" user_choose=input("Whether to log out of the system, please press 1, if not, please press 2:") if user_choose=="1": print("You have successfully logged out, thank you for your support!") else: print("Please continue your selection!") def welcom_system(): print("============================================") print(" Welcome to Mihayou Bank Self-Service ATM system ") print("============================================") def jiemian(): print("1.Check account 2.deposit") print("3.withdraw money 4.Sign out") print("=============================================") def dengluzhuce(): print("1.login account 2.Register an account") """user-interface""" while True: welcom_system() dengluzhuce() user_key1 = input("Please enter your action:") if user_key1 == "1": NewUser = login_user_system() if NewUser is None: continue while True: jiemian() user_key = input("Please enter your action:") if user_key == "1": search_money() elif user_key == "2": add_money() elif user_key == "3": take_money() elif user_key == "4": save(bankuser) login_out() break elif user_key1 == "2": create()
The program runs as follows:
=======================================
Welcome to Mihayou Bank Self-service ATM System
=======================================
1. Login account
Please enter your action: 1
Please enter your account number: susu
Please enter your 6-digit password: 666666
Dear vip user susu, hello, you have successfully logged in, welcome to Mihayou Bank! Please do the following!
----------------------------------------—
1. Inquiry account
3.Withdrawal 4. Logout
=======================================
Please enter your action: 1
You still have 4000 yuan in your account
1. Inquiry account
3.Withdrawal 4. Logout
=======================================
The following is omitted
The code can be fetched and run by itself