Over the course of these challenges, you will develop your own banking app.
Your app will allow users to:
Sign up
Withdraw Money
Deposit Money
Display their balance
Pay someone with an existing account
Each stage will be a single problem you should be solving, which will add to your existing codebase.
Any underlined text is free for you to personalise however you wish.
Add a welcome message to greet the user when they first load your app
Give the user three options to select from the main menu when they first open the app:
1) Log in
2) Create Account
3) Help
If the user selects the number 3, display some helpful information about how they might get help from the bank's customer support.
If the user selects the number 2, they should be asked to enter their email address.
For an email address to be valid, it must fit the following criteria:
It must contain an @ symbol
It must either end in .co.uk or .com
It must not start with the @ symbol
If the email address is valid, let the user know it is valid.
If the email address is invalid, give them some information on why it might be invalid.
Extension - Allow the user to keep trying new email addresses. If the user types "back", they can be taken back to the main menu.
(Consider writing a function to test the email's validity)
All email addresses of our users will be stored in a text file (user_data.txt), which our app will use to keep track of who has accounts.
(This will also be where we will store passwords in the future, but we won't worry about that for now.)
A user cannot create an account with an email address that they have already created an account with.
Before allowing the user to move on, we need to check that their email address is not currently saved in user_data.txt.
If their email address is not currently stored, tell the user their email address has been approved.
If the email address is already saved in the text file, tell the user that they already have an account, and print out the help message you used in 1.3 if they need help recovering their account.
Extension - Instead of the app just exiting, take the user back to the main menu and allow them to make a new selection from the initial 3 choices.
Disclaimer: Storing usernames and passwords unencrypted in a text file is extremely bad practise, and is used here purely as an exercise in working with files in python. If you are making an actual banking app which will use people's actual money, please do not use this activity as your guide, regardless of how enjoyable it is.
If the user's email address is approved, then they should be asked to create a password.
For a password to be valid, it must fit the following criteria:
It must contain at least one number
It must be at least 10 characters long
It must contain at least one symbol
It must NOT include any vowels
If the password is valid, let the user know it is valid.
If the password is invalid, give them some information on why it might be invalid.
Extension - Allow the user to keep trying passwords. If the user types "back", they can be taken back to the main menu.
(Consider using a function to test the password's validity)
If the user has entered a valid password, their information needs to be stored so that when they go to log in, your app knows what their username and password should be.
Store their email address and password in the text file you have called user_data.txt
The data for each user should be stored on separate lines, in the form:
email,password
email,password
etc.
(TIP: You might need to go back to 2.3 and slightly alter how you are checking existing email addresses after this change)
Once you have saved the user's email and password to the text file, tell the user their account has been created successfully and take them back to the main menu.
If the user selects 1, then they should be prompted to enter their email address and password.
Once the user has entered their email address and password, you need to check this against the users you have stored in user_data.txt
If the username and password are both correct compared to what you have stored in user_data.txt, the app should tell the user they have successfully logged on
If there are any errors, the app should tell the user the information they have entered is wrong.
Take some time to try and break your app - are there any points which don't work when certain data is entered? How might you fix that?
In a document, create 20 tests, making use of Valid, Erroneous, Boundary and Null data.
I have included a Test Log template below which you can take a copy of if you would rather not make your own.
Think about the flow of your app - does it just end abruptly? Should the user have control over when the app closes?
Imagine every time you press "run", you were having to close the app down on your phone and then reload it - that would be a very bad user experience.
How might you make your app more user friendly?
Try and identify one part of your app where it is not user friendly and try to improve it.
import os
os.system("clear")
The above code will allow you to clear the console.
If the user has successfully logged on, clear the console so that all of the previous options, choices and sensitive data is removed from view, giving you a fresh place to put the new options for the logged in user.
Remember, import statements should go at the top of your code.
The first thing displayed to the user will be a welcome message.
This will be something like:
"Welcome " + user + " to your online account hub"
Instead of using the person's whole email address, you will chop off the first section up until the @ symbol.
So if the user's email address was ivan77@gmail.com, the following would be displayed:
Welcome ivan77 to your online account hub
(In the example on the right, I am using the email address test@test.com. In hindsight, I could have used something more realistic...)
We now need to print out the options the user will be able to carry out inside their account.
The following options will be available to any logged in user:
Display Balance
Withdraw Money
Deposit Money
Transfer Money
Show Recent Transactions
Log Out
Prompt the user to enter the number of the option they would like to choose.
If the user enters a 6, you should clear the console and return the user to the main menu.
While you are at it, add a 4th option to the main menu, allowing the user to exit completely from the application if they want to.
Now this is added, this should be the only way the program ends. Any other stopping of the program should be treated as an error in the structure / logic of your program.
In section 2.5, you wrote code to create the user's account, adding their email and password to a text file, which you can then use to check when someone tries to log in.
We are going to add to what happens when an account is created. For this to be smooth, it would be better to have all of the account creation code in it's own function.
So before we go any further, define a function - def create_account(): - and put all of the code you have so far for creating a user's account in there.
Now, if we ever want to add to or change what happens when an account is created, we can go straight to this function.
Don't forget to use your function - create_account() - in the appropriate place in your program.
We will need to keep track of all transactions on our user's accounts, so when we create an account, we need to create a text file that we can store all transactions for that individual user.
In order to know who's account it is, we shall make the filename the user's email address.
This means you will need to add some code to your create_account() function which creates a text file, called users's_email.txt
Now we are going to add some code to handle what happens if the user chooses option 3 - deposit money.
We have created a text file to keep a log of when money is put into and taken out of the account, so using this will be important in this step.
Our text file will keep track of each transaction, one transaction per line, and it have the following structure for each new line added to it:
[Timestamp (Date)] [Type (Char)] [Amount (Float)]
For example, if I were to deposit £50 into the account on New Year's Day, the record in the log might look like this:
01/01/2021 D 50.00
You might decided to include the specific time of the transaction as well:
01/01/2021 13:42 D 50.00
It doesn't matter if you use the precise time or not, but it is important that whatever you choose, you are consistent with it.
It is important that between each piece of data, we have a space, so that we can split these up when we get our program to read through the transactions later on.
You will notice the Type is just a single character, in the example above a "D" - this lets us know that the amount specified (50.00) is a deposit. We will use "W" for withdrawal and "T" for transfer.
(You might notice in the example, I also have the character "C" - this is a log that was created when the account was created. My bank gives new customers a free £100 for signing up with us, because I am nice like that!)
You need to add code that will add a new line to the user's transaction log file (the one we created in the last step, with their email as the name of the file), in the format specified above.
Need help getting the current time and date in python? Check out the link below:
Ensure that you are outputting a message to the user confirming their deposit. You might also think about clearing the screen before and after the message to make a smoother and clearer experience for the user.
In order to display the balance for the user, you will need to write some code which will read through the transaction file, and keep a running total as you add all the deposits and subtract all the withdrawals and transfers.
We haven't written any code to allow the user to make withdrawals and transfers yet, but that doesn't stop us from being able to anticipate them and account for them at this stage. We have already decided that withdrawals will be represented by "W" in the log, and Transactions a "T".
On the account screen, if the user presses 1, they should be shown their balance for 5 seconds, before being returned to the account screen.
Try and write a function that just gets the balance and returns it (Doesn't clear screen or print - you can do this in a different part of your code). We will be able to use this function again in the next step when we look at withdrawing money.
Withdrawals will be programmed in a very similar way to how you have done to deposits, with two major differences:
Withdrawals will be added to the log with a "W" instead of a "D"
Withdrawals can only be made if the user has enough money in their account
This should be fairly straightforward, especially as you wrote a function that gets the current balance of the user in the previous step.
You just need to compare the user's balance to how much they want to withdraw, and if the amount they want to withdraw is higher than the amount they have, then you will have to deny their request.
If they do have enough money in their account, then you will add a new line to their transaction log file.
Either way, you should ensure you are printing messages to the screen letting the user know what has happened.