Bank management System project using mysql and python

Suriya Ravichandran

About this Bank management project:

It is simple bank management project .Create a bank account ,deposite money ,withdraw money and view account details this process will be performed this project .Then the data will be store in mysql database.This program using only python programming and mysql

How to create this project:

1. Download and install xampp server from https://www.apachefriends.org/download.html
2.Start xampp server. Open phpmyadmin in your browser
3.Install mysql connector using
    Pip install mysql-connector-python
4.Then write a python code 

How to download and install Xampp server in windows

1.Open your web browser search .Download  xampp for windows.





3.Download new version for windows installer


4. After Download click to open 


5. click next to install xampp








6.Click finish button


7.xampp is successfully install in your computer


How to use xampp and mysql :

1.Click start to apache server


2. click start to mysql


3.click mysql admin


4.phpmyadmin was successfull run web browser



Create a database and table in mysql:

1.Click new 


2. Enter Database name Bank and click create


3. click SQL 

4.Type command to create a table into bank database

CREATE TABLE accounts (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  balance DECIMAL(10, 2) DEFAULT 0
);


5. Then scroll down and click Go button


4.Database and table will be created sucessfully



To connect database in python program:

1.Create folder in your computer ex:"bank management system"
2.Open VS code choose folder bank management system
3.create bank.py file


4.click terminal in VS code 

Install package:

 mysql-connecter-python
decimal

Command:

"pip install mysql-connector-python"
"pip install decimal128"

5.After download you will import package on your program

importmysql.connector
import decimal
 
6. write program to connect database

import mysql.connector
import decimal

# Connect to the MySQL database
db = mysql.connector.connect(
    host="localhost",
    user="root",
    password="",
    database="bank"
)

# Create a cursor object to interact with the database
cursor = db.cursor()

# Function to create a new bank account
def create_account():
    name = input("Enter your name: ")
    balance = float(input("Enter initial balance: "))

    # Insert account details into the database
    insert_query = "INSERT INTO accounts (name, balance) VALUES (%s, %s)"
    values = (name, balance)
    cursor.execute(insert_query, values)
    db.commit()

    print("Account created successfully!")

# Function to deposit money into an account
def deposit():
    account_id = int(input("Enter account ID: "))
    amount = decimal.Decimal(input("Enter amount to deposit: "))

    # Check if the account exists
    select_query = "SELECT * FROM accounts WHERE id = %s"
    cursor.execute(select_query, (account_id,))
    account = cursor.fetchone()

    if account is not None:
        # Update the account balance
        new_balance = account[2] + amount
        update_query = "UPDATE accounts SET balance = %s WHERE id = %s"
        cursor.execute(update_query, (new_balance, account_id))
        db.commit()

        print("Deposit successful!")
    else:
        print("Account not found!")

# Function to withdraw money from an account
def withdraw():
    account_id = int(input("Enter account ID: "))
    amount = decimal.Decimal(input("Enter amount to withdraw: "))

    # Check if the account exists
    select_query = "SELECT * FROM accounts WHERE id = %s"
    cursor.execute(select_query, (account_id,))
    account = cursor.fetchone()

    if account is not None:
        if account[2] >= amount:
            # Update the account balance
            new_balance = account[2] - amount
            update_query = "UPDATE accounts SET balance = %s WHERE id = %s"
            cursor.execute(update_query, (new_balance, account_id))
            db.commit()

            print("Withdrawal successful!")
        else:
            print("Insufficient funds!")
    else:
        print("Account not found!")

# Function to display the account details
def display_account():
    account_id = int(input("Enter account ID: "))

    # Check if the account exists
    select_query = "SELECT * FROM accounts WHERE id = %s"
    cursor.execute(select_query, (account_id,))
    account = cursor.fetchone()

    if account is not None:
        print("Account ID:", account[0])
        print("Name:", account[1])
        print("Balance:", account[2])
    else:
        print("Account not found!")

# Main menu
while True:
    print("\nBank Management System")
    print("1. Create Account")
    print("2. Deposit")
    print("3. Withdraw")
    print("4. Display Account")
    print("5. Exit")

    choice = input("Enter your choice: ")

    if choice == '1':
        create_account()
    elif choice == '2':
        deposit()
    elif choice == '3':
        withdraw()
    elif choice == '4':
        display_account()
    elif choice == '5':
        break
    else:
        print("Invalid choice!")

# Close the database connection
db.close()

To run this program click terminal type "python bank.py" press enter



Output:

Run program output


1.create Account output:


2.Deposit output:


3.withdraw output:


4.display account output:


5.exit output:



Data will be stored successfully in data base








Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send