ATM machine with Python
A beginner’s project on writing Python codes that mimics an ATM machine function for — password creation, cash deposit, cash withdrawal, view customer transaction history, search customer profile and create customer profile.
I started off with creating a randompassword function that, as it’s name suggests generate random password. The generated password is between 8–12 in length, with the combination of uppercase, lowercase and digits.
And then an admin’s interface is created.
Since this is an admin’s interface, limited functions are made available, mostly for profile creation and viewing customer’s past records.
This is followed by creating customer profile, which require these information to be available — first name, last name and address. Username is created by concatenating first 2 characters of last name with first name. If username is not in existing lists of usernames, a new username will be created. Elsewise, the username will be appended with an integer.
Password will be generated using the randompassword function.
The customer’s profile will be saved in a text file that looks like the snip below.
Below is an example on how the interface would like while in action.
Next is viewing customer’s transaction history.
For choice 2, python takes username input from admin to search for transactionhistory txt file.
If file exists and not empty, python prints information in the file. Otherwise, a new transactionhistory file is created, and python returns that there is no transaction history for specific customer. In the event if file exists but empty, python will also return that there is no transaction history.
For example, customer Kamini Premanthan with username: PrKamini has previous existing transaction history.
Here’s the output.
Here’s an output for newly created customer Bell Leong, username: LeBell1 whom has not made any transaction.
Admin can also search for customer’s history using any available particulars. Code is written to read cust_profile.txt, and return lines containing searched particulars input by admin.
In the following example we search for any customer who resides in KL.
Another example searching name: Bell.
Now lets proceed to customer’s interface.
Get gyiernahfufieland’s stories in your inbox
Join Medium for free to get updates from this writer.
Depositcash is a function created to read deposit amount made by customer and update existing balance.
Code is written to get deposit amount and username from customer. Username must be provided to search for balance txt file or create new file. Deposit amount will be added to existing balance in file, and new balance will be stored in the file. Once done, the deposit amount, previous balance and new balance will also be stored in the transaction history file.
Withdrawal cash function is written to read customer’s withdraw amount and make updates to existing balance in txt file.
Code is written to get withdrawal amount and username from customer. Withdrawal amount will then be deducted from existing balance and new balance will be stored in txt file.
If withdrawal amount is more than existing balance, python will return that there is insufficient funds to proceed.
Balance function is written to check for customer’s existing balance. Username has to be provided to search for customer’s file and any information in the file will be read. If there is no existing balance in the file, python will return that there is no balance left.
Customer has to first login into an account to proceed. Both username and password provided will be searched in cust_profile.txt and if do not exist, python will return that the information provide is incorrect.
If both username and password provided are correct, python will return login successful.
Main interface after login where customer get to choose between — deposit money, withdraw money, check balance or check transaction history.
Validation is done on choice made. If wrong choice provided, python returns wrong choice made and checks if customer wants to proceed.
In the following example, customer Elynn has made deposit of 3456 to her account. As there is no prior transaction made by this customer, the new balance remains the same.
A new balance file created by customer’s username.
Transaction history file is also created, and store latest transaction made.
In the next example, customer has requested to withdraw 20 from balance. Since balance is sufficient, withdrawal process is successful.
Next the customer request to withdraw more money, 4000. As we know the existing balance is 3456. Since withdraw amount is more than balance, withdrawal process is not successful.
The procedure for checking balance and transaction history will be similar with admin’s interface.
And … that’s the end of my first Python project. There were some flaws with the code when I tested it, for example on the username function there may be duplicated username created sometimes. I do wish to come back to this project again when I learn more to further improvise it.
But until then, tata !
The Python codes can be found here.









