Professional Documents
Culture Documents
Stack operations
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
Coding:
Output:
***STACK DEMONSTRATION***
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter your choice:1
Enter the item to push:5
***STACK DEMONSTRATION***
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter your choice:1
Enter the item to push:9
***STACK DEMONSTRATION***
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter your choice:1
Enter the item to push:3
***STACK DEMONSTRATION***
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter your choice:3
3 <-top
9
5
***STACK DEMONSTRATION***
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter your choice:2
Deleted item is: 3
***STACK DEMONSTRATION***
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter your choice:2
Deleted item is: 9
***STACK DEMONSTRATION***
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter your choice:4
THANK YOU
Result:
PRACTICAL -17
MYSQL-1
Write and Execute the SQL command for the following
Aim: To Understand the use of DDL and DML commands.
1. Create and open Database named MYORG
mysql> create database MYORG;
mysql> use MYORG;
Database changed
mysql> create table Emp (EmpId int primary key,EmpName varchar(20) not null,
Designation varchar(20),DOJ date,Sal int check(Sal>1000),Comm int);
5. Add one column Email of data type VARCHAR and size 30 to table Emp.
mysql> alter table Emp add Email varchar(20);
9. Write a query to display EmpName and Sal of employees whose salary are greater than
or equal to 2200
mysql> select EmpName,Sal from Emp where sal>=2200;
+------------------+---------------+
| EmpName | Sal |
+-----------------+----------------+
| MR.MAHADEVAN | 2985 |
| MR.BINA | 2850 |
| MR.AMIR | 5000 |
| MR.SHIVANSH | 2450 |
| MR.SCOTT | 3000 |
+-------------------------+---------+
10. Write a query to display details of employs who are not getting commission.
mysql> select * from Emp where Comm is NULL;
+-------+--------------+-------------+------------+------+------+
| EmpId | EmpName | Designation | DOJ | Sal | Comm |
+-------+--------------+-------------+------------+------+------+
| 8369 | MR.SMITH | CLERK | 1990-12-18 | 800 | NULL |
| 8566 | MR.MAHADEVAN | MANAGER | 1991-04-02 | 2985 | NULL |
| 8698 | MR.BINA | MANAGER | 1991-05-01 | 2850 | NULL |
| 8839 | MR.AMIR | PRESIDENT | 1991-11-18 | 5000 | NULL |
| 8882 | MR.SHIVANSH | MANAGER | 1991-06-09 | 2450 | NULL |
| 8888 | MR.SCOTT | ANALYST | 1992-12-09 | 3000 | NULL |
+-------+--------------+-------------+------------+------+------+
11. Write a query to display employeename and salary of those employees who
don’t have their salary in range of 2500 to 4000.
mysql> select Empname, Sal From Emp Where Sal not between 2500 and 4000;
+-------------+------+
| empname | sal |
+-------------+------+
| MR.SMITH | 800 |
| MR.ANYA | 1600 |
| MR.SETH | 1250 |
| MR.MOMIN | 1250 |
| MR.AMIR | 5000 |
| MR.KULDEEP | 1500 |
| MR.SHIVANSH | 2450 |
+-------------+------+
12. Write a query to display the name of employee whose name contains “A” as
third alphabet in Ascending order of employee names.
mysql> select EmpName from Emp where EmpName like " __A%" order by
Empname;
13. Write a query to display the sum of salary and commission of employees as “Total
Incentive” who are getting Commission.
mysql> select sal+comm As "Total Incentive" From Emp where comm is not NULL;
+-----------------+
| Total Incentive |
+-----------------+
| 1900 |
| 1750 |
| 1650 |
| 1500 |
+-----------------+
14. Write a query to display details of employs with the text “Not given”, if
commission is null.
mysql> SELECT EmpID,EmpName,Designation,DOJ,Sal,'Not Given' AS 'Comm'
FROM EMP WHERE Comm IS NULL;
+-------+--------------+-------------+------------+------+-----------+
| EmpID | EmpName | Designation | DOJ | Sal | Comm |
+-------+--------------+-------------+------------+------+-----------+
| 8369 | MR.SMITH | CLERK | 1990-12-18 | 800 | Not Given |
| 8566 | MR.MAHADEVAN | MANAGER | 1991-04-02 | 2985 | Not Given |
| 8698 | MR.BINA | MANAGER | 1991-05-01 | 2850 | Not Given |
| 8839 | MR.AMIR | PRESIDENT | 1991-11-18 | 5000 | Not Given |
| 8882 | MR.SHIVANSH | MANAGER | 1991-06-09 | 2450 | Not Given |
| 8888 | MR.SCOTT | ANALYST | 1992-12-09 | 3000 | Not Given |
+-------+--------------+-------------+------------+------+-----------+
6 rows in set (0.00 sec)
5.Display the Designation wise list of employees with name, Sal and Date of Joining.
8.Set the commission as 100 who are not getting any commission.
9.Delete all the records who is working as “Salesman” and salary more than 1500.
mysql> delete from emp where Designation='SALESMAN' and sal>1500;
Query OK, 1 row affected (0.02 sec)
12.Write the command to round off value 15.93 to nearest ten’s i.e. 20.
mysql> SELECT ROUND(15.93,0);
+----------------+
| ROUND(15.93,0) |
+----------------+
| 16 |
+----------------+
1 row in set (0.00 sec)
13. Write the command to return the substring from the main string.
15.Write command to print the day of the week of your birthday in the year 2019.
mysql> select dayname('2019-08-11');
+-----------------------+
| dayname('2019-08-11') |
+-----------------------+
| Sunday |
+-----------------------+
1 row in set (0.03 sec)
2.Display the name of Employees along with their Designation and Department Name.
mysql> select EmpName,Designation,DeptName from Emp,Dept where
Emp.DeptId=Dept.DeptId;
+--------------+-------------+----------+
| EmpName | Designation | DeptName |
+--------------+-------------+----------+
| MR.SMITH | CLERK | SALES |
| MR.ANYA | SALESMAN | PERSONEL |
| MR.SETH | SALESMAN | PERSONEL |
| MR.MAHADEVAN | MANAGER | ACCOUNTS |
| MR.MOMIN | SALESMAN | PERSONEL |
| MR.BINA | MANAGER | ACCOUNTS |
| MR.AMIR | PRESIDENT | PERSONEL |
| MR.KULDEEP | SALESMAN | ACCOUNTS |
| MR.SHIVANSH | MANAGER | SALES |
| MR.SCOTT | ANALYST | SALES |
+--------------+-------------+----------+
10 rows in set (0.00 sec)
AIM- To Write a program to Integrate SQL with Python by creating the database and table.
Codings:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="likis")
mycursor=mydb.cursor()
mycursor.execute("CREATE DATABASE School")
mycursor.execute("show databases")
for x in mycursor:
print(x)
mycursor.execute("use School")
mycursor.execute("create table student (RollNo int(5) Primary key, Name char(15))")
print("Table created")
PRACTICAL 21
Mysql connectivity-Inserting and Displaying
AIM- To Write a program to Integrate SQL with Python by inserting and displaying the
records.
Codings:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="likis",database="School"
)
mycursor=mydb.cursor()
PRACTICAL 22
Mysql connectivity- Searching and Updating
AIM- To Write a program to Integrate SQL with Python by searching the record and updating it.
Codings:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="likis",database="School
")
mycursor=mydb.cursor()
PRACTICAL 23
Mysql connectivity-Searching and Deleting
AIM- To Write a program to Integrate SQL with Python by searching the record and deleting it.
Codings:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="likis",database="School
")
mycursor=mydb.cursor()
PRACTICAL 24
Random number generator
Aim:
Write a random number generator that generates random numbers between 1 and 6
(simulates a dice).
Codings:
import random
def roll_dice():
print (random.randint(1, 6))
print("""Welcome to my python random dice program!
To start press enter! Whenever you are over, type quit.""")
flag = True
while flag:
user_prompt = input(">")
if user_prompt.lower() == "quit":
flag = False
else:
print("Rolling dice...\nYour number is:")
roll_dice()
PRACTICAL- 25
Most commonly occurring words
AIM- Write a program to Take a sample of ten phishing e-mails (or any
text file) and find most commonly occurring word(s)
Codings:
file =open("Email.txt","r")
content=file.read()
max=0
max_occuring_word=""
occurances_dict={}
words=content.split()
for word in words:
count=content.count(word)
occurances_dict.update({word:count})
if (count>max):
max=count
max_occur_word= word
print("Most occuring word is:", max_occur_word)
print("No. of times it is occuring:", max)
print(occurances_dict)