You are on page 1of 38
COMPUTER SCIENCE. PRACTICAL EXERCISES 2022-23 ‘CLASS - XII PERFORM ARITHMETIC ‘To write a menu driven Python Program to perform Arithmetic operations (+, /) based on the users choice. SOURCE CODE: princOT AGEN Jprine("2. subtraction") Iprinc(r3. woieiplicatson") fprine(r4. Division") jopteint (input ("Enter your chosce:")) laine (input ("Enter the First Mmber:")) fpeint cinput¢ |.¢ optmen: oma Print ("The Addition of two number $a:",e) Joie opemnz: ceed PRINE ("The Subtraction of two number 4s: Joris ope=s: math Print ("The Multiplication of two mumber is:",e) Jerie optwma: Te baw0: Hint ("Enter any other nuaber other than 0") PEINE(The Division of two muaber 4s Jerse print (*Tavalid option’ Result: ‘Thus, the above Python program is executed successfully and the output is verified. Bun=1; 1, Adddition 2. Subtraction 3. Multiplication 4. Division Enter your choice:1 Enter the First Number:10 Enter the Second Nunber:23 The Addition of two number is: BUN-2 1. Adddition 2. Subtraction 3. Multiplication 4. Division Enter your choice:4 Enter the First Numbes Enter the Second Number:0 33 Enter any other number other than 0 ‘To write a Python Program to display Fibonacci Series up to ‘n’ numbers, jo=int (input ("How many Fibonacci numbers you want to display?")) £ no ane data th]) tataeyss anata ‘rint("The searched Eaployes ninber is not found") reetese) latasn Program, lereate() [searent) Results ‘Thus, the above Python program is executed successfully and the output Is verified, ‘SAMPLE OUTPUT: PYTHON PROGRAM EXECUTED OUTPUT: Enter Employee Nunber:1 Enter Employee Name:Anand Enter Employee Salary:23000 Do you want to continue (y/n) ?:¥ Enter Employee Number:2 Enter Employee Name:Akash Enter Employee Salary:25000 Do you want to continue (y/n) Enter Employee Number:3 Enter Employee Nane:Balu Enter Employee Salary:27000 Do you want to continue (y/n) ?:¥ Enter Employee Nunber:4 Enter Employee Name:Bavya Enter Employee Salary:29000 Do you want to continue (y/n) ?:y Enter Employee Number:5 Enter Employee Name:Mano} Enter Employee Salary: 35000 Do you want to continue (y/n) ?:n Enter Employee nunber to search:3 Employee Deatils are: Mane: Balu Salazy: 27000.0 AM: ‘To write a Python program to implement Stack using a list data-structure SOURCE CODE: wlesint input ("Enter the element which you want to push:")) Stick: appendtele) ‘see poPO: ee Stackmet + DEINE ("Stack Ls apty/Undertiow") [Print ("The deleted element 1s:*,Stack-popt)) doe PEEKO. topeten Stack) -1 Deine (othe top most element of Stack is:*,Stack{topl) ee Dispo: open (Stack) -1 Deine (the stack elements are:") or A in range top,-1y-1): eine (Seacklst) seacket) Prine ("stack Operations”) Princesa. posi") Peinet-3. Pebe) Sptninenpee viner your cotee:")) “Sano P08) am cpa epteinput Do you want to perform another stack operstion(y/a)?:") Result: ‘Thus, the above Python program is executed successfully and the output is verified. ‘SAMPLE OUTPUT: ‘Python Program Executed Output: Stack operations 2) oP 3) pReK 4, Display, Enter your choice:1 Enter the element which you want to push:10 Do you want to perform afother stack operation (y/n) ?:¥ Stack Operations i. pose 4. Dispay, Enter your choice:1 Enter the element which you want to push:20 Do you want to perform another stack operation(y/n) ?:y Stack Operations, 4. Display Enter your choice:1 Enter the element which you want to push:30 Do you want to perform another stack operation (y/2)?:y Stack Operations 4. Display Enter your choice:3 ‘The top most element of Stack ts: 30 Do you want to perform another stack operation(y/n)?:¥ Stack operations 3. PEEK 4. Display Enter your choice:2 3 4, Display Enter your choice: to Do you want to perform another stack operation (y/n) ?:y another stack operation(y/n) ?:n EX.NOL13. DATE: CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (INSERTING RECORDS AND DISPLAYING RECORDS) AIM: ‘To write a Python Program to integrate MYSQL with Python by inserting records to Emp table and display the records Salaryeine (input (Enter teployes salary (Query="DISERT ITO EMP VAGUES((),"()","()", 1)" format Oo Mano, Gondor, Salazy) ‘optainput "Do you want to add another employes detaiisty/1):*) loveryerseiscr * row mee"; leirsexecute Query) lastaccur.fetehali eines) Result: “Thus, the above Python program is executed successfully and the output is verified, SAMPLE OUTPUT: Python Executed Program Output: Enter Employee Nunber:1 Enter Employee Name:Arun Enter Employee Gender (M/E) :M Enter Employee Salary:20000 Record Stored Successfully Do you want to add another employes Enter Employee Nuaber:? Enter Employee Name:Bala Enter Employee Gender (M/F) :M Enter Employee Salary:25000 Record Stored Successfully Do you want to add ancther employee Enter Employee Nuaber:3 Enter Employee Nane:Bavya Enter Employee Gender (M/F) :F Enter Employee Salary:27000 Record Stored Successfully Do you want to add another employes Enter Employee Nuaber:4 Enter Employee Nane:Saravanan Enter Employee Gender (M/F) :M Enter Employee Salary:29000 Record Stored Successfully Do you want to add another employee (1, ‘Arun’, '*, 20000) (2, ‘Bala’, 'M*, 25000) (3, ‘Bavya’, "F, 27000) (4) ‘Saravanan’ ,/"M", 29000) details (y/n) details (y/n): dotaiis(y/n}: details (y/n}: part CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON {SEARCHING AND DISPLAYING RECORDS) ‘To write a Python Program to integrate MYSQL with Python to search an Employee using EMPID and display the record If present in already existing table EMP, iF not display the appropriate message ‘SOURCE CODE: [impart mysql. connector |conmayeqi connector connect (hoste! localhost! usarnamem’ root! pasavorde! root! databasen' employees! print ase Print (Weleone to Employee Search Screen") Eetar(setesescevecereeerenvescreresennees} Nosint input ("Enter the employee number to search:*)) (Qsorye'SELDcE + FROM IMP WHERE! EXDIDe{) "format Oo) (crr-exeoute avery) datancur.fetchone() rine (data) * prine(Recond not Found! 1") leon.ctose) Result: ‘Thus, the above Python program is executed successfully and the output is verified. SAMPLE OUTPUT: Python Executed Program Output: RUN Welcome to Employee Search Screen Enter the employee number to search:2 (2, "Bala, 'M', 25000) un =2: Welcome to Employee Search Screen Enter the employee number to search:505 Record not Found!!! batt CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON ‘(UPDATING RECORDS) AIM: ‘To write a Python Program to integrate MYSQI. with Python to search an Emplayee Using EMPID and update the Salary of an employee if present in already existing table EMP, if not display the appropriate message. SOURCE CODE: sport myagl connector Print C-welcome to Eaployes detail update Soren") Bovine (apa (unter the employee number to Upsata:")) SeNEnecate eaeey) Setanoue,fetshone Pest tases) Tew_Saleint (input "Ester the tow Salary of an tnmployee:")) (GisUronse bar SE! EALARY=(} WHERE EoGYOe()"- format ew_Sa, Mo) ‘er execute 03) brint (Employee Salary Updated Successfully") Gae'stunct + row Bae” deeonear etebait 0 Result: ‘Thus, the above Python program Is executed successfully and the output is verified. elcone to Employee detail update Screen Do'you want’ to update the Salary of the above employee (y/a)?+y near the lew Salary of an Employee: 30000, Enployee Salary Updated Successfelly 3 saavya’, "e!, S000) Enter the employee number to Update:500 Record not Found!!! ‘SOL COMMANDS EXERCISE -1 To write Queries for the following Questions based on the given table: Rolino | Name | Gender | Age | Dept DOA. 1 [Arun | M 24 | COMPUTER | 1997-01-10 2 [-Ankie_[— ae 21—[ HISTORY — | 1998-03-24 3 [ Anu —[—F 20 [HIND 1996-12-12 |“ Bala [a0 19 | NULL [1999-07-01 5 | Charan [Mt 18 | HINDI_|1997.09-05 | 250 6 | Deepa | F 19 | HisToRY [1997-06-27 | 300 7 | Dinesh_| Mt 22 | COMPUTER | 1997-02-25 | 210 B| Usha | F 23 [NULL 1997-07-31 | 200. (a) Write 2 Query to Create a new database in the name of “STUDENTS ‘Sol:mysql> CREATE DATABASE STUDENTS; (©) Write a Query to Open the database "STUDENTS! ‘Sol:mysqb> USE STUDENTS; (e) Write « Query to create the above table called: Info Sol: mysql> CREATE TABLE STU(Rollno int Primary key Name varchar(10),Gender varchar(3), ‘Age int,Dept varchar(15),DOA date,Fees int); (4) Write « Query to list all the existing database names ‘Sot: mysql> SHOW DATABASES; output: (6) Write 2 Query to List all the tables that exists in the current database. Sok; mysql> SHOW TABLES; output: (9 Write « Query to insert all the rows of above table into Info table, Sol INSERT INTO STU VALUES (1,Arun’/M', 24/COMPUTER'’ 1997-01-10, 120); INSERT INTO STU VALUES (2,Ankit/M, 21, MISTORY,;1998-03-24', 200); INSERT INTO STU VALUES (3,Anu’F, 20,HINDI'’1996-12-12, 300} INSERT INTO STU VALUES (4,Bala,’M', 19, NULL,1999-07-01', 400} INSERT INTO STU VALUES (5,Charan’,M, 18,HINDI,1997-06-277, 250}; INSERT INTO STU VALUES (6,Deepa''F', 19,HISTORY’'1997-06-27', 300} INSERT INTO STU VALUES (7,Dinesh’ M’, 22, COMPUTER’ 1997-02-25), 210); INSERT INTO STU VALUES (8,Usha',F, 23, NULL, 1997-07-31’, 200} (a) Write « Query to display all the details ofthe Employees from the above table ‘STU. Sok: mysql> SELECT * FROM STU; output (@) Write a query to Rolino, Name and Department ofthe students from STU table. Sol: ‘mysql> SELECT ROLLNO,NAME,DEPT FROM STU; Bx.No: 17. ‘SQL COMMANDS EXERCISE - 2. DATE: AIM: To write Queries for the following Questions based on the given table: Rolino | Name | Gender | Age | Dept DOA Fees 1 [Arun | M 24 | COMPUTER | 1997-01-10 | 120 2 |Ankie_[— ae 21[HIsTORY — | 1998-03-24 | 200 2 | "Anu | F 20 [HIND 1996-12-12 | 300. 3 —|“-Bala_[ a0 19 [NULL 1999-07-01 | — 400 S| Charan [we 18 HINDE 1997.09.05 | 250 6] Deepa | F 19 | HISTORY | 1997-06-27 | 300 7 | Dinesh | Mt 22 | COMPUTER | 1997-02-25 | 210. 8 | Usha [—F 23 [NULL 1997-07-31 | 200 (a) Write « Query to select distinct Department fom STU table. Sol: ‘mysql> SELECT DISTICT(DEPT) FROM STU; utp (0) To show all information about students of History department. Sol: mysqb>SELECT * FROM STU WHERE DEPT“"HISTORY'; outpu (6) Write a Query to list name of female students in Hindi Department. ‘Sok: mysql> SELECT NAME FROM STU WHERE DEPT='HINDI AND GENDER=F'; " =| (q) Write « Query to list name of the students whose ages are between 18 to 20. Sol: mysql> SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20; Quepuc: (6) Write « Query to display the name of the students whose name is starting with 's Sol ‘mysql> SELECT NAME FROM STU WHERE NAME LIKE A%'; output: (f) Write « query to list the names of those students whose name have second alphabet 'n’in thei| mysql> SELECT NAME FROM STU WHERE NAME LIKE "N°; To write Queries for the following Questions based on the given table: Rolino | Name | Gender | Age | Dept DOA 1 [Arun] M 24 | COMPUTER | 1907-01-10 2 |-Ankie_[ ae 21 [HISTORY — | 1998-03-24 2 | "Anu | F 20 [HIND 1996-12-12 3 —|“-Bala_[ a0 19 [NULL 1999.07.01, S| Charan [we 18 HINDE 1997.09.05 | 250 6 | Deepa | F 19 | HISTORY | 1997-06-27 | 300 7 | Dinesh | Mt 22 | COMPUTER | 1997-02-25 | 210. 8 | Usha [—F 23 [NULL 1997-07-31 | 200 (a) Write 2 Query to delete the details of Roll number is 8 Sol mysql> DELETE FROM STU WHERE ROLLNO=8; Output (After Del io (©) Write « Query to change the fess of Student to 170 whose Roll number is 1, ifthe existing fess is less than 130, ‘Sol: mysql> UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130; OutputiAfter Update): (6) Write « Query to-add a new column Area of type varchar in table STU: Sok: ‘mysql> ALTER TABLE STU ADD AREA VARCHAR(20}; output: (4 Write a Query to Display Name of all students whose Area Contains NULL. Sol; mysql> SELECT NAME FROM STU WHERE AREA IS NULL; uy (6) Write a Query to delete Area Column from the table STU. Sol mysql> ALTER TABLE STU DROP AREA; outpu (9 Write « Query to delete table from Database Sol ‘mysql> DROP TABLE STU; outpu AIM: To write Queries for the following Questions based on the given table: "TABLE: STOCK Pao | Pname _[Deode | Qty | UnitPrice | StockDate 5008 | Ballpoint pen | 102 | 100" [10 2021-03-31 5003__| Gel pen premium | 102 [150 [15 2021.01.01 5002 | Peneil 1o1_[125 [4 2021-02-18 5006 | Seale 101 [200 [6 2020-01-01 5001 | Eraser 102[210 [3 2020-03-19 5004 | Sharpner 102 [60 —|s. 2020-12-09 5009 | Gel pen lassie | 103 | 160 | 8 2022-01-19 ‘TABLE: DEALERS Deode | name 101 | Sakthi Stationeries 103 sic Stationeries 102 Indian Book Hotse (a) To display the total Unit price ofall the products whose Deode as 102. ‘mysql> SELECT SUM(UNITPRICE) FROM STOCK GROUP BY DCODE HAVING ‘DCODE=102; Output: (0) To display details ofall products in the stock table in descending order of Stock date. sol mysql> SELECT * FROM STOCK ORDER BY STOCKDATE DESC; (e) To display maximum unit price of products for each dealer individually as per deode from the table Stock. Sol: mysql> SELECT DCODE,MAX(UNITPRICE) FROM STOCK GROUP BY DCODE; ‘Output: (4) To display the Pname and Dname from table stock and dealers Sol: mysql> SELECT PNAME,DNAME FROM STOCK S,DEALERS D WHERE S.DCOD! output:

You might also like