Fidelity bank of new code for balance inquiry

Here is a sample code for a balance inquiry system in Fidelity Bank of Nigeria:

Language: Python Database: MySQL

Assumptions:

Code:

import mysql.connector
from getpass import getpass

# Database connection settings
username = 'your_username'
password = 'your_password'
host = 'localhost'
database = 'fidelity_bank'

# Establish database connection
cnx = mysql.connector.connect(
    user=username,
    password=password,
    host=host,
    database=database
)

# Create a cursor object
cursor = cnx.cursor()

def get_balance(account_number):
    # Query the database to retrieve the account balance
    query = "SELECT balance FROM accounts WHERE account_number = %s"
    cursor.execute(query, (account_number,))
    result = cursor.fetchone()
    if result:
        return result[0]
    else:
        return None

def main():
    print("Fidelity Bank Balance Inquiry System")
    print("-----------------------------------")

    # Get the account number from the user
    account_number = input("Enter your account number: ")

    # Check if the account number is valid
    query = "SELECT * FROM accounts WHERE account_number = %s"
    cursor.execute(query, (account_number,))
    result = cursor.fetchone()
    if result:
        # Get the account balance
        balance = get_balance(account_number)
        if balance:
            print(f"Your account balance is: {balance:.2f}")
        else:
            print("Error: Unable to retrieve account balance.")
    else:
        print("Error: Invalid account number.")

    # Close the database connection
    cnx.close()

if __name__ == "__main__":
    main()

How to use the code:

  1. Replace your_username, your_password, localhost, and fidelity_bank with your actual database credentials and settings.
  2. Run the code using Python (e.g., python balance_inquiry.py).
  3. Enter your account number when prompted.
  4. The system will display your account balance if the account number is valid and the account exists in the database.

Note: This is a basic example and you should consider implementing additional security measures, such as encryption and secure password storage, to protect sensitive customer information.