cs record
cs record
Aim : Write a menu driven program in Python to implement a stack using a list data structure.
Algorithm:
Step 1: Start
Step 2: Create an empty list and three user-defined functions push( ) , pop( ) and disp( ) to insert,
delete and display the elements in the stack.
Push( ):
Create an empty list and append the data’s in the list using append function
s.append(data)
Pop( ):
Delete the last element and display the deleted element using the pop( ) function
dn = s.pop()
Disp( ):
Algorithm:
Step 1: Start
Step 2: Create an empty list and three user-defined functions push( ) , pop( ) and disp( ) to insert,
delete and display the elements in the stack.
Push( ):
o Create an empty list and append the data’s in the list using append function
s.append(data)
Pop( ):
iflen(s)==0:
print('Stack is empty')
o Delete the last element and display the deleted element using the pop( ) function
dn = s.pop()
Disp( ):
Rules:
1. Start by inserting '' ( '' in the stack
2. If character == operand, put in postfix expression
3. If character == operator, put in stack
4. If scanned operator priority (eg '' * '') > top operator priority (eg '' + ''), push in stack
5. If scanned operator priority (eg '' + '') < top operator priority (eg '' * ''), pop till
priority[scanned] becomes > priority[top]
6. If '' ) '' , encountered, pop till '' ( ''
Aim:
Write a program to implement a stack for the employee details (empno,
name).
Algorithm:
Step 1: Start
Step 2: Create an empty list and four user-defined functions push( ) , pop( ) display() and isEmpty()
) to insert, delete and display the elements in the stack.
Push( ):
o Create an empty list and append the data’s in the list using append functiong
stk.append(data)
Pop( ):
17.
Aim: Write a Program to integrate SQL with Python by importing the MySQL module and create a record of
employee and display the record.
Algorithm:
Step 1: Start
Step 2: To check the working of python mysql connectivity import the module and connect with the
database.
importmysql.connector
con=mysql.connector.connect(host="localhost",user='root',password="12345",
database="employee")
Step 3: Start querying the database
cur.execute("Create table EMPLOYEE(EMPNO int, NAME varchar(10), DEPARTMENTvarchar(20),
SALARY float)")
Step 4: Input the values in the table and display the result.
Step 5: Stop
18.
Aim: Write a Program to integrate SQL with Python by importing the MYSQL module to search an
employee number in table employee and display record, if empno not found display appropriate
message.
Algorithm:
Step 1: Start
Step 2: To check the working of python mysql connectivity import the module and connect with the
database.
importmysql.connector
con=mysql.connector.connect(host="localhost",user='root',password="12345",
database="svvv")
cur = con.cursor()
Step 3: Enter the employee no to search for and display the details of the Employee
query="select * from employee where empno={}".format(eno)
cur.execute(query)
result = cur.fetchall()
Step 4: Stop
19.
Aim: Write a Program to integrate SQL with Python by importing the MYSQL module to update the
employee record of entered empno.
Algorithm:
Step 1: Start
Step 2:To check the working of python mysql connectivity import the module and connect with the
database.
Import mysql.connector
con=mysql.connector.connect(host="localhost",user='root',password="12345",
database="svvv ")
cur = con.cursor()
Step 3: Enter the Emp.No to update the details of the employee.
Step 4: Check for the emp.no and update the new details in the table and commit. Else display the
message "Sorry! Empno not found "
Step 5: Stop
20.
Aim: Program to integrate SQL with Python by importing the MYSQL module to delete therecord of
entered employee number.
Algorithm:
Step 1: Start
Step 2:To check the working of python mysql connectivity import the module and connect with the
database.
Import mysql.connector
con=mysql.connector.connect(host="localhost",user='root',password="12345",
database="svvv ")
cur = con.cursor()
Step 3:Enter the Emp.No to delete the details of that employee.
Step 4: Check if that emp.no exist and delete the details of that particular employee and commit. Else
display the message "Sorry! Empno not found "
Step 5: Stop