{"id":972,"date":"2021-06-10T23:35:27","date_gmt":"2021-06-10T18:05:27","guid":{"rendered":"https:\/\/cbsepython.in\/?p=972"},"modified":"2023-12-28T09:58:04","modified_gmt":"2023-12-28T04:28:04","slug":"bank-management-python-project","status":"publish","type":"post","link":"https:\/\/cbsepython.in\/bank-management-python-project\/","title":{"rendered":"Bank Management- Python Project for class 12 MySQL Connectivity"},"content":{"rendered":"<h3>Bank Management- Python Project Class 12<\/h3>\n<p>&nbsp;<\/p>\n<p>Source Code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#https:\/\/cbsepython.in\r\nprint(\"****BANK TRANSACTION****\")\r\n#creating database\r\nimport mysql.connector\r\nmydb=mysql.connector.connect (host=\"localhost\",user=\"root\", passwd=\"admin\")\r\nmycursor=mydb.cursor()\r\nmycursor.execute(\"create database if not exists bank\")\r\nmycursor.execute(\"use bank\")\r\n#creating required tables \r\nmycursor.execute(\"create table if not exists bank_master(acno char(4) primary key,name varchar(30),city char(20),mobileno char(10),balance int(6))\")\r\nmycursor.execute(\"create table if not exists banktrans(acno char (4),amount int(6),dot date,ttype char(1),foreign key (acno) references bank_master(acno))\")\r\nmydb.commit()\r\nwhile(True):\r\n    \r\n    print(\"1=Create account\")\r\n    print(\"2=Deposit money\")\r\n    print(\"3=Withdraw money\")\r\n    print(\"4=Display account\")\r\n    print(\"5=Exit\")\r\n    ch=int(input(\"Enter your choice:\"))\r\n    \r\n#PROCEDURE FOR CREATING A NEW ACCOUNT OF THE APPLICANT\r\n    if(ch==1):\r\n        print(\"All information prompted are mandatory to be filled\")\r\n        acno=str(input(\"Enter account number:\"))\r\n        name=input(\"Enter name(limit 35 characters):\")\r\n        city=str(input(\"Enter city name:\"))\r\n        mn=str(input(\"Enter mobile no.:\"))\r\n        balance=0\r\n        mycursor.execute(\"insert into bank_master values('\"+acno+\"','\"+name+\"','\"+city+\"','\"+mn+\"','\"+str(balance)+\"')\")\r\n        mydb.commit()\r\n        print(\"Account is successfully created!!!\")\r\n        \r\n#PROCEDURE FOR UPDATIONG DETAILS AFTER THE DEPOSITION OF MONEY BY THE APPLICANT\r\n    elif(ch==2):\r\n        acno=str(input(\"Enter account number:\"))\r\n        dp=int(input(\"Enter amount to be deposited:\"))\r\n        dot=str(input(\"Enter date of Transaction: YYYY-MM-DD \"))\r\n        ttype=\"d\"\r\n        mycursor.execute(\"insert into banktrans values('\"+acno+\"','\"+str(dp)+\"','\"+dot+\"','\"+ttype+\"')\")\r\n        mycursor.execute(\"update bank_master set balance=balance+'\"+str(dp)+\"' where acno='\"+acno+\"'\")\r\n        mydb.commit()\r\n        print(\"money has been deposited successully!!!\")\r\n#PROCEDURE FOR UPDATING THE DETAILS OF ACCOUNT AFTER THE WITHDRAWL OF MONEY BY THE APPLICANT\r\n\r\n    elif(ch==3):\r\n        acno=str(input(\"Enter account number:\"))\r\n        wd=int(input(\"Enter amount to be withdrawn:\"))\r\n        dot=str(input(\"enter date of transaction: YYYY-MM-DD \"))\r\n        ttype=\"w\"\r\n        mycursor.execute(\"insert into banktrans values('\"+acno+\"','\"+str(wd)+\"','\"+dot+\"','\"+ttype+\"')\")\r\n        mycursor.execute(\"update bank_master set balance=balance-'\"+str(wd)+\"' where acno='\"+acno+\"'\")\r\n        mydb.commit()\r\n\r\n#PROCEDURE FOR DISPLAYING THE ACCOUNT OF THE ACCOUNT HOLDER AFTER HE\/SHE ENTERS HIS\/HER ACCOUNT NUMBER\r\n    elif(ch==4):\r\n        acno=str(input(\"Enter account number:\"))\r\n        mycursor.execute(\"select * from bank_master where acno='\"+acno+\"'\")\r\n        for i in mycursor:\r\n            print(i)\r\n    else:\r\n        break\r\n        \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Output:<\/p>\n<p>&nbsp;<\/p>\n<pre>****BANK TRANSACTION****\r\n1=Create account\r\n2=Deposit money\r\n3=Withdraw money\r\n4=Display account\r\n5=Exit\r\nEnter your choice:1\r\nAll information prompted are mandatory to be filled\r\nEnter account number:1001\r\nEnter name(limit 35 characters):\"Jitendra Singh\"\r\nEnter city name:\"New Delhi\"\r\nEnter mobile no.:1234567890\r\nAccount is successfully created!!!<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>Enter your choice:2\r\nEnter account number:1001\r\nEnter amount to be deposited:5000\r\nEnter date of Transaction: YYYY-MM-DD 2021-10-10\r\nmoney has been deposited successully!!!<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>Enter your choice:3\r\nEnter account number:1001\r\nEnter amount to be withdrawn:1000\r\nenter date of transaction: YYYY-MM-DD 2021-10-11<\/pre>\n<p>&nbsp;<\/p>\n<pre>Enter your choice:4\r\nEnter account number:1001\r\n('1001', '\"Jitendra Singh\"', '\"New Delhi\"', '1234567890', 4000)\r\n1=Create account\r\n2=Deposit money\r\n3=Withdraw money\r\n4=Display account\r\n5=Exit<\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\">Explanation:<\/span><\/h2>\n<p><span style=\"color: #000000;\">This is a Python code for a basic bank transaction system. It uses a MySQL database to store account and transaction details.<\/span><\/p>\n<p><span style=\"color: #000000;\">The code creates a &#8220;bank&#8221; database if it does not already exist and then creates two tables in the database &#8211; &#8220;bank_master&#8221; and &#8220;banktrans&#8221;. The &#8220;bank_master&#8221; table stores details of each account holder, such as account number, name, city, mobile number, and account balance. The &#8220;banktrans&#8221; table stores transaction details, such as account number, amount, date of transaction, and transaction type (deposit or withdrawal).<\/span><\/p>\n<p><span style=\"color: #000000;\">The code then presents a menu to the user with the following options:<\/span><\/p>\n<ol>\n<li><span style=\"color: #000000;\">Create account<\/span><\/li>\n<li><span style=\"color: #000000;\">Deposit money<\/span><\/li>\n<li><span style=\"color: #000000;\">Withdraw money<\/span><\/li>\n<li><span style=\"color: #000000;\">Display account<\/span><\/li>\n<li><span style=\"color: #000000;\">Exit<\/span><\/li>\n<\/ol>\n<p><span style=\"color: #000000;\">If the user chooses to create an account, the code prompts for details such as account number, name, city, and mobile number. It then inserts the details into the &#8220;bank_master&#8221; table and sets the account balance to 0.<\/span><\/p>\n<p><span style=\"color: #000000;\">If the user chooses to deposit money, the code prompts for the account number and amount to be deposited. It then inserts a transaction record into the &#8220;banktrans&#8221; table with the account number, amount, current date, and transaction type &#8220;d&#8221;. It also updates the account balance in the &#8220;bank_master&#8221; table.<\/span><\/p>\n<p><span style=\"color: #000000;\">If the user chooses to withdraw money, the code prompts for the account number and amount to be withdrawn. It then inserts a transaction record into the &#8220;banktrans&#8221; table with the account number, amount, current date, and transaction type &#8220;w&#8221;. It also updates the account balance in the &#8220;bank_master&#8221; table.<\/span><\/p>\n<p><span style=\"color: #000000;\">If the user chooses to display an account, the code prompts for the account number and then retrieves and displays the account details from the &#8220;bank_master&#8221; table.<\/span><\/p>\n<p><span style=\"color: #000000;\">If the user chooses to exit, the code breaks out of the while loop and ends.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\">Functions used in this Python code<\/span><\/h2>\n<ol>\n<li><span style=\"color: #000000;\"><code>mysql.connector.connect()<\/code>: This function is used to create a connection to a MySQL database. It takes in several parameters, such as the host, user, and password, and returns a MySQLConnection object.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>cursor()<\/code>: This method is called on a MySQLConnection object and returns a Cursor object. A Cursor object is used to interact with a MySQL database.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>execute()<\/code>: This method is called on a Cursor object and is used to execute a MySQL query. It takes a single parameter, which is the MySQL query to be executed.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>commit()<\/code>: This method is called on a MySQLConnection object and is used to commit any changes made to the database. This is necessary to ensure that changes made to the database are permanent.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>input()<\/code>: This function is used to take user input. It prompts the user to enter a value and returns the input as a string.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>str()<\/code>: This function is used to convert a value to a string.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>int()<\/code>: This function is used to convert a value to an integer.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>break<\/code>: This keyword is used to break out of a loop.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>if...elif...else<\/code>: This is a conditional statement used to execute different blocks of code depending on the condition. The <code>if<\/code> block is executed if the condition is true, the <code>elif<\/code> block is executed if the previous condition is false and the current condition is true, and the <code>else<\/code> block is executed if all the previous conditions are false.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>for<\/code> loop: This is a loop that is used to iterate over a sequence of values. In this code, it is used to iterate over the result of a MySQL query and print the values.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>primary key<\/code>: This is a column or group of columns in a database table that uniquely identifies each row. In this code, the &#8220;acno&#8221; column in the &#8220;bank_master&#8221; table is set as the primary key, which means that each account number can only appear once in the table.<\/span><\/li>\n<li><span style=\"color: #000000;\"><code>foreign key<\/code>: This is a column or group of columns in a database table that references the primary key of another table. In this code, the &#8220;acno&#8221; column in the &#8220;banktrans&#8221; table is set as a foreign key that references the &#8220;acno&#8221; column in the &#8220;bank_master&#8221; table. This ensures that each transaction in the &#8220;banktrans&#8221; table corresponds to a valid account in the &#8220;bank_master&#8221; table.<\/span><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #ff0000;\">You should also check:<\/span><\/h2>\n<ul>\n<li>\n<h3><a href=\"https:\/\/cbsepython.in\/viva-questions-for-class-12-computer-science-python-with-answer\/\">Important questions for Practical Viva<\/a><\/h3>\n<\/li>\n<li>\n<h3><a href=\"https:\/\/cbsepython.in\/cbse-computer-science-practical-file-for-class-12\/\">Class 12 Practical File for Term 2 Practical Examination<\/a><\/h3>\n<\/li>\n<li>\n<h3><a href=\"https:\/\/cbsepython.in\/category\/python-projects\/\">More Python Projects<\/a><\/h3>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Bank Management- Python Project Class 12 &nbsp; Source Code: #https:\/\/cbsepython.in print(&#8220;****BANK TRANSACTION****&#8221;) #creating database import mysql.connector mydb=mysql.connector.connect (host=&#8221;localhost&#8221;,user=&#8221;root&#8221;, passwd=&#8221;admin&#8221;) mycursor=mydb.cursor() mycursor.execute(&#8220;create database if not exists bank&#8221;) mycursor.execute(&#8220;use bank&#8221;) #creating required tables mycursor.execute(&#8220;create table if not exists bank_master(acno char(4) primary key,name varchar(30),city char(20),mobileno char(10),balance int(6))&#8221;) mycursor.execute(&#8220;create table if not exists banktrans(acno char (4),amount int(6),dot date,ttype char(1),foreign [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-972","post","type-post","status-publish","format-standard","hentry","category-python-projects"],"_links":{"self":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/comments?post=972"}],"version-history":[{"count":0,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/posts\/972\/revisions"}],"wp:attachment":[{"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/media?parent=972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/categories?post=972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbsepython.in\/wp-json\/wp\/v2\/tags?post=972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}