Explore

Close
Python Programs Share

ATM Program In Python With Source Code

ATM Program In Python With Source Code

Want to know how to make an atm program in python then you are at the right place today. In this python tutorial I will show you how to make an atm program in python with source code so read this guide till the end.

An ATM is a machine from which you can withdraw your money from your bank account directly in cash. We will create a similar python atm program from which we can withdraw money and see our balance.

It is going to be a simple program. I will show you everything on how to do it and provide you with the atm program python code, so follow me till the end.

Below are the most searched queries on this ATM program that we will solve:

  • ATM program in python using while loop.
  • ATM program in python using if else.
  • ATM program in python using function.

Many people want this program made using while loops or function or if else, but what I have done is combined all of them and created this program so you don’t have to go anywhere now.

Complete ATM Program Code In Python


# PYTHON ATM PROGRAM BY PYTHONDEX 
# Visit https://pythondex.com for more information

user = {
    'pin': 1234,
    'balance':1000
}

def widthdraw_cash():
    while True:
        amount = int(input("Enter the amount of money you want to widthdraw: "))
        if amount > user['balance']:
            print("You don't have sufficient balance to make this widthdrawal")
        else:
            user['balance'] = user['balance'] - amount
            print(f"{amount} Dollars successfully widthdrawn your remaining balance is {user['balance']} Dollars")
            print('')
            return False

def balance_enquiry():
    print(f"Total balance {user['balance']} Dollars")
    print('')


is_quit = False

print('')
print("Welcome to the Pythondex ATM")

pin = int(input('Please enter your four digit pin: '))     

if pin == user['pin']:
    while is_quit == False:
        print("what do you want to do")
        print(" Enter 1 to Widthdraw Cash \n Enter 2 for Balance Enquiry \n Enter 3 to Quit")
        
        query = int(input("Enter the number corresponding to the activity you want to do: "))
        
        if query == 1:
            widthdraw_cash()
        elif query == 2:
            balance_enquiry()
        elif query == 3:
            is_quit = True

        else:
            print("Please enter a correct value shown")
else:
    print("Entered wrong pin")

Above is the complete code for this atm program. I will explain each part of the code in a later part. First, let’s run this program. You should have python installed on your computer if you don’t have read this: Install and setup python.

To run this python atm program, follow the below steps:

  • Create a new folder for this atm python project.
  • Open it in a code editor of your choice.
  • Create a python file with an ending .py extension.
  • Copy the above code and paste it in your file.

Now you have the code and you are ready to run this program so open a command prompt or terminal at the project folder location and paste the below command to run.


python filename.py

The above command will run this program. It will welcome you and ask you to enter what you want to do below is an example output of this program.

Output


Welcome to the Pythondex ATM
Please enter your four digit pin: 1234
what do you want to do
 Enter 1 to Widthdraw Cash
 Enter 2 for Balance Enquiry
 Enter 3 to Quit
Enter the number corresponding to the activity you want to do: 2
Total balance 1000 Dollars

what do you want to do
 Enter 1 to Widthdraw Cash
 Enter 2 for Balance Enquiry
 Enter 3 to Quit
Enter the number corresponding to the activity you want to do: 1000
Please enter a correct value shown
what do you want to do
 Enter 1 to Widthdraw Cash
 Enter 2 for Balance Enquiry
 Enter 3 to Quit
Enter the number corresponding to the activity you want to do: 2
Total balance 1000 Dollars

what do you want to do
 Enter 1 to Widthdraw Cash
 Enter 2 for Balance Enquiry
 Enter 3 to Quit
Enter the number corresponding to the activity you want to do: 1
Enter the amount of money you want to widthdraw: 1000
1000 Dollars successfully widthdrawn your remaining balance is 0 Dollars

what do you want to do
 Enter 1 to Widthdraw Cash
 Enter 2 for Balance Enquiry
 Enter 3 to Quit
Enter the number corresponding to the activity you want to do: 2
Total balance 0 Dollars

what do you want to do
 Enter 1 to Widthdraw Cash
 Enter 2 for Balance Enquiry
 Enter 3 to Quit
Enter the number corresponding to the activity you want to do: 1
Enter the amount of money you want to widthdraw: 1
You don't have sufficient balance to make this widthdrawal
Enter the amount of money you want to widthdraw: 0
0 Dollars successfully widthdrawn your remaining balance is 0 Dollars

what do you want to do
 Enter 1 to Widthdraw Cash
 Enter 2 for Balance Enquiry
 Enter 3 to Quit

If you have run this program then you can see that we have successfully created an atm program using python.

If you are still not able to run this program on your computer due to technical errors or you are using a mobile than you can use this online python compiler to test this code.

Python ATM Program Code Explanation.

We have how to run this program now. Let’s see and understand how this program works. I will go through each part of the program so you understand it. You need to know the basics of python to understand this program.

I have used a combination of while loops, functions and if else statements to create this program, so you need to know how they work.


user = {
    'pin': 1234,
    'balance':1000
}

First, I have declared a user dictionary which stores the pin and balance. This program does not support multiple users, but you can easily add that functionality.


print("Welcome to the Pythondex ATM")

pin = int(input('Please enter your four digit pin: '))     

Then we have a print statement which welcomes the user and an input where the user is asked to enter a 4 digit pin. The pin is hard-coded in the user dictionary.


if pin == user['pin']:
    while is_quit == False:
        print("what do you want to do")
        print(" Enter 1 to Widthdraw Cash \n Enter 2 for Balance Enquiry \n Enter 3 to Quit")
        
        query = int(input("Enter the number corresponding to the activity you want to do: "))
        
        if query == 1:
            widthdraw_cash()
        elif query == 2:
            balance_enquiry()
        elif query == 3:
            is_quit = True

        else:
            print("Please enter a correct value shown")
else:
    print("Entered wrong pin")
        

After entering the pin it checks the pin if it matches, If it does not match then it will print the wrong pin entered message in the else statement. If it matches, then it will go inside the if statement.

As you can see, inside the if statement we have while loop which will run until is_quit variable becomes True which is false by default.

Now it will ask the user what you want to do and the response the user should give are as follows:

  • Enter 1 to withdraw cash
  • Enter 2 for balance enquiry
  • Enter 3 to quit the program.

Then we check the response from the user in the if else statement and if it matches the response number it goes and runs the functions.


def widthdraw_cash():
    while True:
        amount = int(input("Enter the amount of money you want to widthdraw: "))
        if amount > user['balance']:
            print("You don't have sufficient balance to make this widthdrawal")
        else:
            user['balance'] = user['balance'] - amount
            print(f"{amount} Dollars successfully widthdrawn your remaining balance is {user['balance']} Dollars")
            print('')
            return False

Above is the withdraw money function, which will run if the query is 1. Inside the withdraw function it asks the user to enter the amount they want to withdraw and if the amount entered is available in their balance they will get the cash.

But if not then it will print an insufficient balance message and it will ask them to enter the amount to be withdrawn.


def balance_enquiry():
    print(f"Total balance {user['balance']} Dollars")
    print('')

Above is the balance enquiry function, which will run if the query matches 2. This function will print the balance of the user.

Lastly we have another query which if the user enters 3 the atm program will quit. This was the whole atm python program.

Summary

This was the tutorial on how to create an atm program in python. I hope you found this tutorial helpful and useful. Do share this with your friends who might be interested in this python program.

Here are some more python tutorials that will interest you:

I hope you found what you were looking for from this python tutorial and if you want more tutorials like this, do join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂