0% found this document useful (0 votes)
2 views4 pages

Pythonlab Progr

The document contains a Python script for stack operations (push, pop, peek, display) and a MySQL database interaction for managing employee records. It allows users to perform various stack operations and store or retrieve employee data from a database. The script includes a menu-driven interface for user interaction with both the stack and the database functionalities.

Uploaded by

asishsai67
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Pythonlab Progr

The document contains a Python script for stack operations (push, pop, peek, display) and a MySQL database interaction for managing employee records. It allows users to perform various stack operations and store or retrieve employee data from a database. The script includes a menu-driven interface for user interaction with both the stack and the database functionalities.

Uploaded by

asishsai67
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

def push(st1, item):

[Link](item)
top=len(st1)-1
def display():
if st==[]:
print("Stack is Empty")
else:
top=len(st)-1
for i in range(top,-1,-1):
print(st[i])

def pop():
if st==[]:
print("Stack is Empty")
else:
s=[Link]()
print("The Deleted item is",s)
if len(st)==0:
top=None
else:
top=len(st)-1
def peek():
if st==[]:
print("Stack is Underflow")
else:
top=len(st)-1
print("The Top most item is:",st[top])
#main()
st=[]
top=None
while True:
print("stack operation".center(60))
print("Press 1. Push".center(58))
print("press 2. pop".center(55))
print("Press [Link]".center(55))
print("press 4. display".center(60))
print("Press 5. exits".center(58))
print()
print()
ch=int(input("Enter your Choice"))
if ch==1:
lm=int(input("Enter the Limit to insert value in stack"))
for i in range(0,lm):
item=int(input("Enter the value to be inserted"))
push(st,item)
elif ch==2:
pop()
elif ch==3:
peek()
elif ch==4:
display()
elif ch==5:
break
else:
print("Enter the valid choice")
import [Link] as mycon
con = [Link](host='localhost',user='root',password="root123")
cur = [Link]()
[Link]("create database if not exists company")
[Link]("use company")
[Link]("create table if not exists employee(empno int, name varchar(20),dept
varchar(20),salary int)")
[Link]()
choice=None
while choice!=0:
print("1. ADD RECORD ")
print("2. DISPLAY RECORD ")
print("0. EXIT")
choice = int(input("Enter Choice :"))
if choice == 1:
e = int(input("Enter Employee Number :"))
n = input("Enter Name :")
d = input("Enter Department :")
s = int(input("Enter Salary :"))
query="insert into employee values({},'{}','{}',{})".format(e,n,d,s)
[Link](query)
[Link]()
print("## Data Saved ##")
elif choice == 2:
query="select * from employee"
[Link](query)
result = [Link]()
print("%10s"%"EMPNO","%20s"%"NAME","%15s"%"DEPARTMENT","%10s"%"SALARY")
for row in result:
print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3])
elif choice==0:
[Link]()
print("## Bye!! ##")
else:
print("## INVALID CHOICE ##")

You might also like