- ATM Function Requirements
-
Import Python Random Module
- What does the random module/package do in Python?
- Create Class and Define Functions
- What is a class?
- How to define a function?
- Define the main() Function
- ATM Process Creation Using while True
The first step is to brainstorm what basic transactions are completed at an ATM?
Some of the function that one can complete at an ATM are given below:
- Input user pin for authentication
- Check account balance
- Deposit funds
- Withdraw funds
- Create random generated transaction id
- Account interest rate and Monthly accused interest rate
Ques. What does the random module/package do in Python?
Ans. The random module allows a program to create random numbers by using the random.randint() function.
import random
Ques. What is a Class?
Ans. A class is used for creating objects. By creating objects, the objects have variables and a behavior that's associated with them.
A class is created with the keyword class. Once the class is created, the object within the class will then be called the instance of the class.
Ques. How to define a function?
Ans. Now we take the requirements that we created from the above and create functions. We can define the functions to provide the given functionality of the program.
The function blocks are started with def keywords and followed with the function name and parenthesis, such as def getId(self).
We must create the main() function because it’s only executed when the Python program is executed. Also, we could import a Python program as a module,
but the main() method will not execute. The entry point of any program is the main() function, but the interpreter of python will execute the source file code sequentially.
In addition, it will not call any method if it’s not within the code. This is why the main() method has a technique,
so that the main() method will be executed when the program is executed directly and not when the module is imported.
By creating the main() method, we will use a range to have all users to enter a 4-digit pin to access their account.
We will use the while True loop because it will loop forever. The while statement will take an expression and execute the body of the loop while the expression is equal to ‘boolean’ of True. As long as the loop stays True, the loop will indefinitely loop.