CBSE CLASS 12

CBSE Class 12 : Python

Revision tour

CBSE Class 12 : Functions

Functions

User defined functions

Resursion

Recursion Examples

CBSE Class 12: Inbuilt Functions

String Inbuilt Functions
Math Inbuilt Functions
Date and Time Inbuilt Functions
Random Module

CBSE Class 12 : Data File Handling

Data File Handling

Character by Character reading
Word by word reading
Line by line reading

CBSE Class 12 : Data Structures

Introduction to Data Structures
Stacks and its Applications
Implementation of Stacks
Queue and its Applications
Implementation of Queue

CBSE Class 12 : Interface Python With SQL

Class 12 Interface Python With SQL

Example : 1 Student Record management

Example :2 Bank Record Management

CBSE Class 12 : Web Development With Django

Introduction To Django

Example 1: To Test Django

Example 2: To Display Welcome Message

Example 3: To Display Data in Table Format

CBSE Class : Communication And Network Concepts

Full Forms

Computer Networks

Wired and Wireless Networks

New Technologies

Network Devices

Network Stack

IP Address

Transmission Control Protocol

Basic Network Tools and Applications

Switching techniques

 

Network topologies

Society Law and Ethics

Society Law and Ethics

Digital Property Rights

LICENSING

CYBERCRIME

Cyber Forensics

Technology And Society

Gender and Disability issues

 

CBSE Class 12 : Sample Papers

Class 12 Python Sample Paper 1
Class 12 Python Sample Paper 1 (Solution)
Class 12 Python Sample Paper 2
Class 12 Python Sample Paper 2 (Solution)

CBSE Class 12 : Practical File

Practical File Programs

CBSE Class 12 :  Python Project

Student management System

Student Management System 2

Banking System

MarkSheet Management System

Stock Management System

Telephone Directory

Digital Directory

Class 12 : Interface Python and MySQL Example 2

To maintain Bank Customer Details Like accno,name, balance, mobno and emailid

To create a bank database

#to create a database
import pymysql
db=pymysql.connect("localhost","root","")
c=db.cursor()
sql="create database bank;"
c.execute(sql)
db.close()

To create a table in the above created database

#to create a table
import pymysql
db=pymysql.connect("localhost","root","","bank")
c=db.cursor()
sql="""
create table banked(
accno char(15),
name char(20),
bal decimal(10),
mobno char(15),
emailid char(20)); """
c.execute(sql)
db.close()

To Insert record in the above created table

#to take input for details and save in database
import pymysql
db=pymysql.connect("localhost","root","","bank")
c=db.cursor()
a=input("enter accno")
n=input("enter name")
b=float(input("enter balance"))
m=input("enter mobno")
e=input("enter emailid")
try:
    c.execute("insert into banked(accno,name,bal,mobno,emailid) values(%s,%s,%s,%s,%s)"(a,n,b,m,e))
    db.commit()
    print("record saved")
except:
    db.rollback()
db.close()

Display all the record from the table

#display the records from table
import pymysql
db=pymysql.connect("localhost","root","","bank")
try:
    c=db.cursor()
    sql='select * from banked;'
    c.execute(sql)
    print("number of rows: ",countrow)
    data=c.fetchall()
    for eachrow in data:
        print(eachrow)
except:
    db.rollback()
db.close()

2nd method to display all the record from the table

#display the records from the table field by field
import pymysql
db=pymysql.connect("localhost","root","","bank")
try:
    c=db.cursor()
    sql='select * from banked;'
    c.execute(sql)
    countrow=c.execute(sql)
    print("number of rows: ",countrow)
    data=c.fetchall()
    print("Accno   Name   Bal   Mobno   Emailid")
    for eachrow in data:
        a=eachrow[0]
        n=eachrow[1]
        b=eachrow[2]
        m=eachrow[3]
        e=eachrow[4]
        print(a," ",n," ",b," ",m," ",e)
except:
    db.rollback()
db.close()

To search a record on the basis of accno (account number of customer)

#search a record by accno field by field
import pymysql
db=pymysql.connect("localhost","root","","bank")
try:
    z=0
    accno=int(input("Enter accno to search"))
    c=db.cursor()
    sql='select * from banked;'
    c.execute(sql)
    print("number of rows: ",countrow)
    data=c.fetchall()
    for eachrow in data:
        a=eachrow[0]
        n=eachrow[1]
        b=eachrow[2]
        m=eachrow[3]
        e=eachrow[4]
        if(a==accno):
            z=1
            print(a,n,b,m,e)
    if(z==0):
        print("Record is not present")
except:
    db.rollback()
db.close()

Search a record on the basis of name of the customer

#search a record by name field by field
import pymysql
db=pymysql.connect("localhost","root","","bank")
try:
    z=0
    name=input("Enter name to search")
    c=db.cursor()
    sql='select * from banked;'
    c.execute(sql)
    print("number of rows: ",countrow)
    data=c.fetchall()
    for eachrow in data:
        a=eachrow[0]
        n=eachrow[1]
        b=eachrow[2]
        m=eachrow[3]
        e=eachrow[4]
        if(n==name):
            z=1
            print(a,n,b,m,e)
    if(z==0):
        print("Record is not present")
except:
    db.rollback()
db.close()

Delete a record on the basis of accno of customer

#searching a record by accno and deleting it
import pymysql
db=pymysql.connect("localhost","root","ct","bank")
try:
    z=0
    accno=int(input("Enter accno to search and delete"))
    c=db.cursor()
    sql='select * from banked;'
    c.execute(sql)
    countrow=c.execute(sql)
    print("number of rows: ",countrow)
    data=c.fetchall()
    for eachrow in data:
        a=eachrow[0]
        n=eachrow[1]
        b=eachrow[2]
        m=eachrow[3]
        e=eachrow[4]
        if(a==accno):
            z=1
            print(a,n,b,m,e)
    if(z==0):
        print("Record is not present")
    else:
        a=accno
        sql1="delete from banked where accno= ",accno
        print(sql1)
        c.execute(sql1)
        db.commit()
except:
    db.rollback()
db.close()

Delete a record on the basis of name of customer

#searching a record by name and deleting it
import pymysql
db=pymysql.connect("localhost","root","ct","bank")
try:
    z=0
    name=input("Enter name to search and delete")
    c=db.cursor()
    sql='select * from banked;'
    c.execute(sql)
    countrow=c.execute(sql)
    print("number of rows: ",countrow)
    data=c.fetchall()
    for eachrow in data:
        a=eachrow[0]
        n=eachrow[1]
        b=eachrow[2]
        m=eachrow[3]
        e=eachrow[4]
        if(n==name):
            z=1
            print(a,n,b,m,e)
    if(z==0):
        print("Record is not present")
    else:
        n=name
        sql1="delete from banked where name= ",name
        print(sql1)
        c.execute(sql1)
        db.commit()
except:
    db.rollback()
db.close()

To search and display records on the basis of balance in account

#search a record by balance field b field
import pymysql
db=pymysql.connect("localhost","root","ct","bank")
try:
    z=0
    bal=float(input("Enter balance to search"))
    c=db.cursor()
    sql='select * from banked;'
    c.execute(sql)
    print("number of rows: ",countrow)
    data=c.fetchall()
    for eachrow in data:
        a=eachrow[0]
        n=eachrow[1]
        b=eachrow[2]
        m=eachrow[3]
        e=eachrow[4]
        if(b==bal):
            z=1
            print(a,n,b,m,e)
    if(z==0):
        print("Record is not present")
except:
    db.rollback()
db.close()