12TH CS TERM 2 - Python
12TH CS TERM 2 - Python
Aim: Write a program to create Lpush() and Lpop() function to do push and pop operation
on a stack using a list e.g. take a student information and push and pop the details
Algorithm:
Step 1: Define a function to checks whether the stack is empty or not
Step 2: Push() Function to Allow additions to the stack
Step 3: Pop() Function to verifies whether the stack is empty or not , use if and else to
allow deletions from the stack
Step 6: Stack menu-driven program by providing choices to the user by using multiple if-
else statements.
Step 7: use input() function for user-based input system, if ,elif,else,nested if these
statements is used for conditional execution.
Step 8: The break command can be executed to break out of the loop and the program
will end.
Source code:
RESULT:
Thus the above program is executed and output is verified successfully.
Program 17: Program to connect with database and store record of employee and display records
Aim:
To write the Program to connect with database and store record of employee and display
records
Algorithm:
Step 1: import mysql connector module
Step 2: Test the connection with the database
Step 3: Create the new database if already not exists
Step 4: Take the input from the user employee number, name, salary and store the values
into variable query
Step 5: Use execute() function to allow SQL piece of code executed like
ADD,DISPLAY,EXIT
Step 6: The output is fetched and returned as a list by fetchall()
Step 7: Use commit() function to Changes saved into database
Step 8: Connection closed (broken) with Database by using close() function.
Source code:
Output:
RESULT:
Thus the above program is executed and output is verified successfully.
Program 18: Program to connect with database and search employee number in table employee
and display record, if empno not found display appropriate message.
Aim:
To write the Program to connect with database and search employee number in table
employee and display record, if empno not found display appropriate message.
Algorithm:
Step 1: import mysql connector module
Step 2: Test the connection with the database
Step 3: Use the Old database which already exists in database
Step 4: Take the input from the user employee number to search.
Step 5: Use execute() function to allow SQL piece of code executed like
SEARCH
Step 6: The output is fetched and returned as a list by fetchall()
Step 7: Use if condition to match the employee number to search, if condition true it
display the matched data employee name, number, salary otherwise display data not found.
SOURCE CODE:
OUTPUT:
RESULT:
Thus the above program is executed and output is verified successfully.
Program 19: Program to connect with database and update the employee record of entered
empno.
Aim:
To write the Program to connect with database and update the employee record of entered
empno.
Algorithm:
Step 1: import mysql connector module
Step 2: Test the connection with the database
Step 3: Use the old database which already exists in database
Step 4: Take the input from the user employee number to update the value
Step 5: Use execute() function to allow SQL piece of code executed like UPDATE
Step 6: The output is fetched and returned as a list by fetchall()
Step 7: Use commit() function to Changes saved into database
Step 8: Use the if condition to match the value employee number, if value matched then
update the employee department and salary only , otherwise it display employee
number not found.
Source code:
Output:
RESULT:
Thus the above program is executed and output is verified successfully.
Program 20: Program to connect with database and delete the record of entered employee
number.
Aim:
To write the Program to connect with database and delete the record of entered employee
number.
Algorithm:
Step 1: import mysql connector module
Step 2: Test the connection with the database
Step 3: Use the old database which already exists in database
Step 4: Take the input from the user employee number to update the value
Step 5: Use execute() function to allow SQL piece of code executed like DELETE
Step 6: The output is fetched and returned as a list by fetchall()
Step 7: Use commit() function to Changes saved into database
Step 8: Use the if condition to match the value employee number, if value matched then
it delete the employee name, number ,department and salary , otherwise it display
employee not found.
Source code:
Output:
RESULT:
Thus the above program is executed and output is verified successfully.