Chose 3 Total Each 1 From
Chose 3 Total Each 1 From
Database creation
mysql> create database classes;
Database changed
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
2 rows in set (0.00 sec)
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
Database changed
+-------------------+
| Tables_in_classes |
+-------------------+
| student |
+-------------------+
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
+-------------------+
| Tables_in_classes |
+-------------------+
| classroom |
| student |
+-------------------+
+--------+--------+-------+----------+
+--------+--------+-------+----------+
| 18 | nitesh | 87 | nikhil |
| 19 | nikhil | 88 | nityam |
+--------+--------+-------+----------+
Database changed
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
+--------+---------+-------+---------+------------+
Database changed
+--------+--------+-------+----------+
+--------+--------+-------+----------+
| 18 | nitesh | 87 | nikhil |
| 19 | nikhil | 88 | niraj |
+--------+--------+-------+----------+
Database changed
+--------+--------+
| name | rollno |
+--------+--------+
| deepak | 15 |
| samita | 17 |
+--------+--------+
if stk==[]:
return True
else:
return False
stk.append(item)
top=len(stk)-1
def Pop(stk):
print("Underflow")
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)
def Display(stk):
if isEmpty(stk):
print("Stack is empty")
else:
top=len(stk)-1
for i in range(top,-1,-1):
print (str(stk[i]))
# executable code
if __name__ == "__main__":
stk=[]
top=None
Push(stk,1)
Push(stk,2)
Push(stk,3)
Push(stk,4)
Pop(stk)
Display(stk)
Output:
Popped item is 4
1
27. Program to implement queue in python using list
def enqueue(data):
queue.insert(0,data)
def dequeue():
if len(queue)>0:
return queue.pop()
def display():
for i in range(len(queue)):
print(queue[i])
# executable code
if __name__=="__main__":
queue=[]
enqueue(5)
enqueue(6)
enqueue(9)
enqueue(5)
enqueue(3)
display()
Output:
6
PYTHON CONNECTIVITY
1.Write a python prog that displays first three row fetched from
student table of my sql database “test”
mycon=sqltor.connect(host=”localhost”,user=”learner”,passwd=”fas
t”,database=”test”)
if mycon.is_connected()==False:
cursor=mycon.cursor()
cursor.execute(“select*from student”)
data=cursor.fetchmany(3)
count=cursor.rowcount
print(row)
mycon.close()
OUTPUT :
(101,’ruhani’,decimal(’76.80’),’A’,’A’,’Pending’)
(102,’george’,Decimal(’71.20’),’B’,’A’,’Submitted’)
(103,’simran’,Decimal(’81.20’),’A’,’B’,’Evaluated’)
2.Write a python program that displays the no of employees hired at
the desired date $ time
import datetime
import mysql.connector
cursor = cnx.cursor()
hire_start = datetime.date(1999, 1, 1)
cursor.close()
cnx.close()
OUTPUT:
..
mycon=pym.connect(“localhost”,”learner”,”fast”,”test”)
cursor=mycon.cursor()
data=cursor.fetchmany(3)
count=cursor.rowcount
print(row)
mycon.close()
output
(101,’ruhani’,decimal(’76.80’),’A’,’A’,’Pending’)
(102,’george’,Decimal(’71.20’),’B’,’A’,’Submitted’)
(103,’simran’,Decimal(’81.20’),’A’,’B’,’Evaluated’)