Computer Science Of Engineering

Simple and practical computer science tutorials, programming guides, and engineering concepts for students and beginners.

Breaking

Sunday, April 26, 2026

Python - ATM mini project using conditions and loops

 

ATM Mini Project Using Conditions and Loops in Python

This beginner project uses:

  • if-else

  • while loop

  • variables

  • input/output

  • basic ATM operations

Functions included:

  1. Check Balance

  2. Deposit Money

  3. Withdraw Money

  4. Exit


Python Code

# ATM Mini Project

balance = 1000   # Initial balance

while True:
    print("\n===== ATM MENU =====")
    print("1. Check Balance")
    print("2. Deposit Money")
    print("3. Withdraw Money")
    print("4. Exit")

    choice = int(input("Enter your choice: "))

    if choice == 1:
        print("Your current balance is:", balance)

    elif choice == 2:
        deposit = int(input("Enter amount to deposit: "))
        balance = balance + deposit
        print("Amount deposited successfully")
        print("Updated balance is:", balance)

    elif choice == 3:
        withdraw = int(input("Enter amount to withdraw: "))

        if withdraw <= balance:
            balance = balance - withdraw
            print("Please collect your cash")
            print("Remaining balance is:", balance)
        else:
            print("Insufficient balance")

    elif choice == 4:
        print("Thank you for using ATM")
        break

    else:
        print("Invalid choice! Please try again")

Step-by-Step Explanation

1. Initial Balance

balance = 1000

This sets starting balance as ₹1000.


2. Infinite Loop

while True:

This keeps ATM running until user selects Exit.


3. ATM Menu

print("1. Check Balance")
print("2. Deposit Money")
print("3. Withdraw Money")
print("4. Exit")

Shows available options.


4. User Choice

choice = int(input("Enter your choice: "))

User selects option using number.


5. Check Balance

if choice == 1:

Displays current account balance.


6. Deposit Money

elif choice == 2:

Adds entered amount to balance.

Example:

₹1000 + ₹500 = ₹1500


7. Withdraw Money

elif choice == 3:

Checks if enough balance is available.

If yes → money withdrawn
If no → shows insufficient balance


8. Exit

elif choice == 4:

Stops the program using:

break

Sample Output

===== ATM MENU =====
1. Check Balance
2. Deposit Money
3. Withdraw Money
4. Exit

Enter your choice: 1
Your current balance is: 1000

Enter your choice: 2
Enter amount to deposit: 500
Amount deposited successfully
Updated balance is: 1500

Enter your choice: 3
Enter amount to withdraw: 700
Please collect your cash
Remaining balance is: 800

Enter your choice: 4
Thank you for using ATM



Viva Questions

Q: Why do we use while True?

To repeat the ATM menu until the user exits.

Q: Why do we use break?

To stop the loop and exit the program.

Q: Why is if withdraw <= balance used?

To check if the user has enough money before withdrawing.

Q: Which concepts are used here?

  • Conditions (if, elif, else)

  • Loop (while)

  • Input/Output

  • Variables


 

No comments:

Post a Comment