0% found this document useful (0 votes)
13 views

Computer science class 12th practical file

Practical file computer science

Uploaded by

alluprabhat123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views

Computer science class 12th practical file

Practical file computer science

Uploaded by

alluprabhat123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 29
INDEX | S.NO AIM DATE Page sign no. 1 Write a python Program to take | 11-04-24 | 04 input for a number , calculate and print its square and cube? 2 ‘Write a python program to take | 19-04-25 | 06 input for 2 numbers, calculate and print their sum, product, difference 3 Write a python program to take 04-25 |07 input for 3 numbers ,Check and oe print the largest number? 4 ‘Write a python program to take | (4-05-24 | 08 input of 2 number and an operator (+,-,%,/). Based on the operator calculate and print the result. 5 Write a python program to take | 1-05-24 | 09 input for a number and print its table? 6 Write a python program totake | (9.(7-24 | 10 input for a number and prints its factorial. 7 | Write a python program to take | 11-07-24 | 11 input for a number check if the entered number is Armstrong or not 8 Write a python program totake | 19.97-24 | 12 input for a number and print its factorial using recursion. 9 Write a python program to 23-07-24) 13 display Fibonacci Sequence using Recursion. 10. | Write a python program to reada | ()3-08-24 | 14 file named “article.txt”, count and print total alphabets in the files Write a python program to maintain book details like book code, book title and price using stacks data structures? (implement push(),. pop() and traverse() functions) 14-8-24 Write a python program to maintain employee details like empno,name and salary using Queues data structure? (implement insert(), delete() and traverse() functions) 21-08-24 Write a python program to read a file named "article.txt", count and print the following: (i) length of the file (total characters in file) (iitotal alphabets (i) total upper case alphabets (iv) total lower case alphabets (v) total digits (vi) total spaces (vii) total special characters 24-08-24 Write a python program to read a file named "article.txt", count and print total words starting with "a" or "A" in the file? 29-08-24 21 Write a python program to read a file named "article.txt", count and print total lines starting with vowels in the file? 04-09-24 22 Write a function to insert a record in table using python and MySQL. 10-09-24 23 interface Write a function to display all the records stored in a table using python and MySQL interface. 15-09-24 24 Write a fanction to search a record stored in a table using python and MysQL interface. 07-10-24 25 Create a student table of a class that contains the record of a student who scored maximum marks in a particular subject using CREATE TABLE and INSERT command in SQL. 09-10-24 26 20 SQL alter table 22-10-24 27 21 UPDATE query in SQL 26-10-24 28 22 ALTER TABLE RENAME column 12-11-24 29 23 ALTER TABLE DROP column 20-11-24 30 Aim: Write a python Program to take input for a number , calculate and print its square and cube? Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM output: RESTART: C:/Users /abc/AppData /Local Programs /Python /Python37-32/Caleulate square and cube py fo Aim: Write a python program to take input for 2 numbers, calculate and print their sum, product, difference Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM t(input("Enter Ist no ")) ot(input("Enter 2nd no ")) s=atb p=a*b itla>b): d=ab els print("Sum = ",s) print("Product = print("Difference = Enter 1st no 5 Enter 2nd no 2 Sum = 7 Product = 10 Difference = 3 Aim: Write a python program to take input for 3 numbers Check and print the largest number? Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM ‘at(input("Enter 1st no ")) int(input("Enter 2nd no ")) c=int(input("Enter 3rd no ")) if(a>b and a>¢): m=a else: if(b>0): m=b else: Enter 1st no 12 Enter 2nd no 13 Enter 3rd no 14 Max no= 14 Aim: Write a python program to take input of 2 number and an operator (+,-,*/). Based on the operator calculate and print the result. Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM a=int(input("Enter 1st no ")) (input("Enter 2nd no")) nput("Enter the operator (+,*,/)") mi print("Product = ",¢) liop=="-") it(@>b): cab cbse caba print( "Difference = ",¢) lit(op=="/") c=a/b print( "Division = ",c) else: print("Invalid operator") Enter Ist no 12 Enter 2nd no 2 Enter the operator (+,-,*,/) / Division = 6.0 Aim: Write a python program to take input for a number and print its table 2 Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM num=int(input("Enter any no ")) while@<=10): table=num*i print(num," * " irit1 Enter any no 5 5*1=5 5*2=10 5*3= 15 5*4= 20 S oureur | 5*5 = 25 ee 5 * 6 = 30 Ss 5*8 = 40 5*9= 45 5 * 10 = 50 Aim: Write a python program to take input for a number and prints its factorial. Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM n=int(input("Enter any no ")) i=1 f=1 while@<=n): Ai 1 print(""Factorial = ",f) | OUTPUT Enter any no 5 [Factorial = 120 Aim: Write a python program to take input for a number check if the entered number is Armstrong or not Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM n=int(input("Enter the number to check :")) al=a s=0 while(n>0): d=n%10 s=s+(d*d*d) int(a/10) 1. ifs print("Armstrong Number") else: print("Not an Armstrong Number") | oure\ Enter the number to check : 12 Not an Armstrong Number (Alternate OUTPUT) - Enter the number to check : 153 Armstrong Number Aim: Write a python program to take input for a number and print its factorial using recursion. Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM coo, #Factorial of a number using recursion def recur_factorial(a) ifn return a bse: return n*recur_factorial(a-1) #for fixed number ‘num = 7 #using user input ‘sum=int(input("Enter any n0 ")) Hcheck if the number is negative ifnum <0: print("Sorry, factorial does not exist for negative numbers") elif num == 0: print("The factorial of 0 is 1") else: print("The factorial of", num, "is", recur_factorial(num)) ‘ourpur- | Enter any no 5 The factorial of 5 is 120 15 Aim: Write a python program to display Fibonacci Sequence using Recursion. Software Used: Python IDLE Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM LODE} der recu_fibo(a): asst return n else retusn(geeur_fibo(a-1) + recur_fibo(a-2)) terms = int(input("Enter upto which term you want to print")) check if the number of terms is valid if (aterms <= 0) print("Plese enter a positive integer") else: print("Fibonacci sequence:") for in range(aterms) print(recur_fibo@)) Enter upto which term you want to print2 Fibonacci sequence: 16 Aim: . Write a python program to read a file named “article.txt”, count and print total alphabets in the files Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM {output | : Hello how are you 12123 bye total lower case alphabets 17 v7 Aim: . Write a python program to maintain book details like book code, book title and price using stacks data structures? (implement push(,. pop) and traverse() functions) Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM def push(): beode=input (“Enter beode ") btitle=input ("Enter btitle ") pricesinput (“Enter price ") ‘bcode,btitle,price) book. append (bk) def pop() if(book==[]): print (*Underflow / Book Stack in empty") else: beode,btitle,price=book-pop() print("poped element is ") print("beode ",beode,” btitle ",btitle," price ",price) def traverse(): if not (boo! nelen oe) for i in range(n-1, print (book{ i}) 1) else print ("Empty , No book to display") hile True: print("1. Push") print("2. Pop") print("3. Traversal") print("4. Exit") 18 traverse() elif(ch==4): print("End") break else print ("Invalid choice") 1. Push 2. Pop 3. Traversal 4, exit Enter your choice 1 Enter beode 101 Enter btitle python Enter price 254 19 Aim: . Write a python program to maintain employee details like empno,name and salary using Queues data structure? (implement insert(), delete) and traverse() functions) Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM add employee delete enployee traverse / display all employees exployee=[] def add_elenent() fempno=input("Enter empno name=input ("Enter name salzinput("Enter sal femp=(enpno,nane, sal) ‘employee. append (emp) def det_elenent() if (employee==[1): print(“Underflow / Employee Stack in empty") else! ‘enpno,nane, sal =employee.pop(0) print(“poped element is") Print("empno ",empno,” name “,nane," salary *,sal) def traverse(): if not (employee==[]) rnslen(employee) for i in range(@,n) ees Mintlenployeet iD) print("Empty , No employee to display") while True: print("1, Add employee") ("2 Delete employes") 20 print(*3. Traversal*) print("4. Gee") heint (nput("Enter your choice “)) if (chen) = 344_element() elif(chse2) ‘del_element()3 elif (eho=3) traverse() elif (chee) print ("End") break else: print("Invalid choice") 1. Add employee 2. Delete employee 3. Traversal 4. Exit Enter your choice 1 Enter empno 101 Enter name Amit Enter sal 45000 a Aim: . Write a python program to read a file named "article.txt", count and print the following: (i) length of the file (total characters in file) (ii)total alphabets (ii) total upper case alphabets (iv) total lower case alphabets (v) total digits (vi) total spaces (vii) total special characters Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM break elses Splesplet prine(“total alphabets 2) Prine(“total upper case alphabets *,ua) prine("total special cheracters spl) # function calling count) 2 welcome (total (‘total (‘total (‘total (total (total to cbsepython. alphabets *, 19) upper case alphabets ', 1) lower case alphabets ", 21) digits *, 0) spaces *, 0) special characters ', 22) 2B Aim: . Write a python program to read a file named "article.txt", count and print total words starting with "a" or "A" in the file? Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM Amit Ankur and Ajay (“total words starting with ‘a’ are ", 4) 24 Aim: . Write a python program to read a file named "article.txt", count and print total lines starting with vowels in the file? Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM Line 1: amit Line 2: owl Line 3: Eat apple a day and stay healthy Line 4: Anmol 25 Aim: . Write a function to insert a record in table using python and MySQL interface Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM def insert data) ‘teake Input for the details and then save the record in the databse nport myaql.connector {go = mysel. connector: comect(hoste" localhost" user="root” parsword="adain") ceiacceaet int input ("Enter roll 99 *)) put(enter ane *) rCinpue(Eater per ")) cvexecute("insert into student (rol1,nane,per) values (8,36,%8)", (40.8) ei ‘db-rollback() close) fnaertdateO) 0) Record saved") Coureur | Enter roll no 101 Enter name amit Enter per 97 Record saved 26 Aim: . Write a function to display all the records stored in a table using python and MySQL interface. Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM def display a1): import mysql connector o try nystl.comector.connect(hoat="localhost! user="roct" passe b.cursor() select * from student; cute(sql) countrow-e-exacute(sql) print(*nunber of rove + *,countrom) ) en beer ueea| Courur number of rows : 2 Roll No Wane Per 102 aaa 99 a01 amit 97 27 Aim: . Write a function to search a record stored in a table using python and MysQL interface. Software Used: Python IDLE and MY SQL Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM {CODE | der search roit() ‘ Inport mysel connector db = mysql. connector. connect (host="localhost* urer="root*,paseuds"adnin”databare-"test") Folleint(input("Enter roll po to search “)) Cs dbceurser() venoeete(eql) . sxecute(eal) runbor of rows" countrow) Fetchadi() Pint Record dot present™) excent: ‘Besrollbeck() decloee() fearchrall() Coureur | Enter roll no to search 101 number of rows : 2 101 amit 97 28 Aim: . Create a student table of a class that contains the record of a student who scored maximum marks in a particular subject using CREATE TABLE and INSERT command in SQL. Software Used: MY SQL(workbench) Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM | OUTPUT eine Name Gender Subject as 29 Aim: . SQL alter table Software Used: MY SQL(workbench) Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM ono [Name Gender | Subject Warke [Sete] 7 vena pw nena 29 ma] 2 vera Ponce 7 a] z a cheney @ a] 2 = © eal 7 waa] = x F ra = wma] 6 aaa F Boe 7 waa] 7 ee PrycatEaiaton @ van] 30 = UPDATE query in SQL. Software Used: MY SQL(workbench) Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM Courur | ouput Rolo [Name [Gender | Subject an | State 7 varey eras | err z vara Pose ee Go 2 sume |r crensiy a | iPass z 7a = en 7a | aren 3 eG Ti [iran $ aaa [F Boy a7___|wirPracen 7 rape [F Pyaeaiaion @ arse 31 - ALTER TABLE RENAME column Software Used: MY SQL(workbench) Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM Enrotementve Name Gender | Subject | Marke 3 soma |F rer [95 a an w Eran 7% 5 7a F i § ee 0007 7 7 fapeet | F Presi acon @ 32 « ALTER TABLE DROP column Software Used: MY SQL(workbench) Hardware Used: Keyboard, Monitor, Mouse , Hard disc, RAM ouput Rollo Name Gender ‘Subject 2 Vial « Payses 3 ‘Saumya F ‘Chemisty a "an w Engish 5 Rashi F Boog 7 varprect F PrysealEaucaton 33

You might also like