0% found this document useful (0 votes)
44 views10 pages

Sample Paper Together With

Together with sample paper

Uploaded by

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

Sample Paper Together With

Together with sample paper

Uploaded by

Arush Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
ee, | Sample Practical Paper 1, WAP # menu program to implement the stack of ‘Ans. def push(1st): nseval(input(‘Enter no, *)) list using concepts of stacks. na=input(‘Enter name *) Ast.append([n,na]) def pop(Ist): if Ist=[]: print (‘UNDERFLOW') else: print('Enployee record’ ,1st.pop(), ‘deleted") def display(1st): if Ist= print( ‘UNDERFLOW') else: for i in range(1en(Ist)-1,-1,-1): print(1st[i]) def peek(1st): if Aste=[]: print ( ‘UNDERFLOW') else: print(1st[len(1st)-1]) consty’ Ast=[] while con: print(*' ‘Press 1 to add records in stack\nPress 2 to delete records in stack\ ecords in stack. Press 4 to return the top most element nPress 3 to display all 1 in stack’’') xeint(input(*Enter your choice ')) if xe-ds push(1st) 100 ageeher waek® Computer Science (Python) —12 display (1st) elif x=*4: peek(1st) else: print("Enter a valid choice") consinput("Press y to continue or any other key to exit’) 2. The given program is used to add a new record in a table customer. CustNO, CustNane, City, Email, Amount You are required to complete the statements so that program can be executed properly. import pymysql def addrecord(): try: r=int(input("Enter Customer Number")) nasinput("Enter Customer Name") ct+input ("Enter City") em=input ("Enter email") at-float(input("Enter amount") #CustNO, CustName, City, Email, Amount query = “INSERT INTO customer(cno, cname, city, email, amount) VALUES (Oth. 0)".format(x, na, ct,em,at) cr. _(query) ‘Python method to send the SOL statement to the database db. () furite the TCL command to save the data into the database print(" Row inserted") except as e: Name of the class to generate the error print(“Error in insertion ",e) Walling Statement _Main()__ ty: ymysql.connect (host="localhost",user=' Toot", password="smsmb") Q #Method to open the cursor object print("Connected Successfully !!!!") Dateer secre #SQL command to open the database Board execute (Data) rint("Database Opened! !!!!") cept Exception as e: rint("Database connection error",e) \ddrecord() we spython method to send the So. stat | Sample Practical Paper 101 execute (Quety ‘enent to the database a) wurite the TCL command to save the except Exception as e: atiane of the class to generate the error curedd. cursor () Method to open the cursor object pata="use board” SOL command to open the database Board 4, wAmenu driven program fo create the database with table m fields: custNO, CustName, City, Email, Arount data into the database ‘ame customer having following ‘The program should add a new record and dis, in Mumbai. inport ‘sConplete the statement with appropriate library nane def display(): try: cr=db. cursor() Tow-cr.execute("Select * from customer") x=cr.fetchall() print("Customer Number No\tCustmerName\t\t\tCity\t\t\témail\t\t\tAnount\n") for row in x: if =="Mumbai": #Statment to compare the record print (“{}\t\t{Ae\eve\e{Ae\e\e{e\e\e{}". (ii) form at (rou 0), rou{2), row [2] row[3], row[4])) ——___ase: fame of the class to generate the error Brint("Error in insertion *,e) ut Statement _Main() play all the records of the customer who lives except ob =pymysql.connect . (host="localhost", user=root", password: "smsnb") Curedb, Q) “Method to open the cursor object Print (“Connected Sucessfully !!!!") Data. 7 ee CECE Ee ; “SQL command to open the database “Board i vl 12 102 Fagecher werh® Computer Science (Python)—' cr-execute (Data) print("Database Openned!!!!!") except Exception as e+ i print ("Database connection error",e) addrecord() pymysal rou[2] Exception (iv) cursor () Use Board 4. The given program is used to connect with MYSQL and show all the record from the tae “Emp” from the database "Test".You are required to complete the statements so tht i, code can be executed properly. inport #Complete the statement with appropriate library name db =pynysql. (host="1ocalhost" ,user="root” ,passuord="snsmb") ‘#Fill the statement with appropriate method cur=db. 0 ‘Method to open the cursor object data="test" print( ) *Method to extract all the record from the cursor object cur.execute(" *) *SOL statement to read all the records from the table secur. fetchall() Print ("All the record of the table") for i in s: print (i) Ans. (i) pymysql (ii) row{2) Gi) Exception (@) cursor (¥) Use Board Sample Practical Paper 103 5, The given program is used to connect with MYSQL and show the name of all the database available in MySQL Server. You are required to complete the statements so that the code can be executed properly. import (i) Complete the statement with appropriate library nane db =pynysql. — (4a) (host="localhost” users "root", password="snsmb") #Fi11 the statement with appropriate method curedb.____() (iid) #Hethod to open the cursor object cur.execute(* ) (av) # Command to display all the database nane print (cur. ) Ww Method to extract all the required from the cursor Ans. (i) pymysql (ii) connect (iii) cursor (iv) show databases (v) fetchall() 6. WAP a menu program to implement the stack of list using concepts of stacks. Ans. def push(Emp): eno-int (input("Enter the Empolyee Number") ename=input ("Enter the Employee Name”) sal-float (input ("Enter the Salary*)) Emp. append([eno, enane, sal]) def pop(Emp): if Emp==[]: print("Under Flow") else: print("Employee Record Deleted”, £mp.pop()) def display(Emp): print(“Underflow! !!") else: print("Employee record in Stack\n") 104 agether week® Computer Science (Python)—12 Ls1en(Emp) for i in range(1-1,-1.-1): print(Emp[(i]) Emp=[] while True: print ("\ni. Pushi\n2, Pop \n3. Display\nd. Exit") ch=int(input ("Enter your choice")) if chestr push (Emp) elif ch==2: pop (Emp) elif ch display (Emp) else: break Output: 1. Push 2. Pop 3. Display 4. Exit Enter your choicel Enter the Empolyee Nunber1 Enter the Employee NameDeyansh Enter the Salary3000000 1. Push 2. Pop 3. Display 4 Exit Enter your choicet Enter the Empolyee Nunber2 Enter the Employee NaneTigesh Enter the Salary4o0000 1. Push 2. Pop 3. Display 4 exit enter your choicel enter the Enpolyee Nunber3 enter the Employee Naneshivaye enter the Salary2300000 w Push 2. Pop 3. Display a. Exit enter your choice? Employee record in Stack [3, ‘Shivaye’, 2300000.0] [2, ‘Tigesh’, 4000.0] [1, ‘Deyansh', 3000000.0] 1. Push 2. Pop 3. Display 4 Exit Enter your choice2 Employee Record Deleted [3, ‘Shivaye’, 2300000.0] 1. Push 2. Pop 3. Display 4. Exit Enter your choice3 Employee record in Stack la, ‘Tigesh', 400000.0) 1, ‘Deyansh', 3000000.0] Lush 2 Pop 3, Display 4 exit & nt "8 your choices Sample Practical Paper 105 puter Science (Python) —12 106 Tagether eocth® COM gram to create the database with table name customer h 7. WA menu driven pros fields: CustNO, CustName, City, Email, Amount m should add a new record and display all the records. The progra ample Practical Paper 107 Howecrenerute(selert © fram customer") veer ferehal lO) PHIAEC Customer Huber no Castner fame OE ry Ot temai L\E\e\témount\n") print CHSESEESE EXEL ESE MENE EF format (rou[O), row[ 1}, cowl 2], rowl 3}, row{4])) except Feception ase ty db = py passuils print ("Conn Data credb. cur Cr execute (Da print ("Data except bee print(* Chior", e) loc «(host host ly localhost 1H your host, u your usernan wb") 8 your mysql password sfully HEE) USE board” 0 a) 6 Openned! 1111") © connection error",e) Main Program while Try print ("Mer + Add \n2. Display") cheint (input (“Enter Choice*)) if elifeh dis cavinpur( if cnes'Nt break © to continue” hed addrecord() 2 splay() els print("Enter valid choices") or cnee'n's ‘The given program is used to connect with MYSQL and show the name of all the tables vailable in MySQL. Server "TEST" database. You are required to complete the statements that the code can be executed properly. 108 Fapceher ewith® Computer Science (Python) —12 (i) #Conplete the statement with appropriate library nane import db =pymysql.. (ii) (host="Localhost", use WFill the statement with appropriate method “root” password: "smsmb") () (di) Method to open the cursor object curedb. data="test" cur. execute (" “edata) (iv) #Command to open the database cur.execute(" ee) ¥), #Conmand to display name of all the tables print (cur.fetchall()) Ans. (i) pymysql (ii) connect (iif) cursor (iv) use (%) show tables

You might also like