SlideShare uma empresa Scribd logo
1 de 34
TEXT FILES
#1 Writing data intotext files using writelines
with open("two.txt","w") as f:
l=[]
ch='y'
x=0
while ch=='y':
l=input("enter list values")
f.writelines(l)
ch=input("do you want to
continue?")
x+=1
print("file created successfully!!!with
",x,"records entered")
enter list values"Suhani",89,"A"
do you want to continue?y
enter list values"Raunak",55,"C"
do you want to continue?y
enter list values"Cia",45,"D"
do you want to continue?n
file created successfully!!!with 3
records entered
#2 Read() method intext files
fr=open("one.txt","r")
data=fr.read()
print("Fileread successfully")
print(data)
fr.close()
File read successfully
My firstline of code
to enter data into a text file
we will do binary files later
#3 Read() method withargument in text files
fr=open("one.txt","r")
data=fr.read(10)
print("Fileread successfully")
print(data)
fr.close()
File read successfully
My firstl
#4 Readline() methodintext files
fr=open("one.txt",'r')
data=fr.readline()
print(data)
print("line read successfully")
fr.close()
My firstline of code
line read successfully
#5 Using read() method in a Text file count number of consonants ,vowels ,digits
and special characters
f=open("one.txt",'r')
data=f.read()
sp,c,d,v=0,0,0,0
L=len(data)
for i in data:
print(i,end='')
if i in ("aeiouAEIOU"):
v+=1
elif i.isalpha():
c+=1
elif i.isdigit():
d+=1
My firstline of code
to enter data into a text file
we will do binary files later
string: My firstline of code
to enter data into a text file
we will do binary files later
Total no. of characters: 86
no. of consonents 39
vowels 26
digits: 0
else:
sp=L-(c+d+v)
print("n string:", data)
print("Totalno. of characters:",L)
print("no. of consonents",c)
print("vowels",v)
print("digits:",d)
print("specialnumbers",sp)
special numbers 21
#6 Using read() method in text file count the number of words in a text file
(SPLIT FUNCTION)
#counting the number of words in a
text file
f=open("one.txt",'r')
data=f.read()
l=data.split()
w=len(l)
print("contents of the file are n",
data)
print("Number of words:", w)
Contents of the file are
My firstline of code
to enter data into a text file
we will do binary files later
Number of words: 18
#7 Replace eachsignby ‘#’ sign, display the string and write intoa new file
#Read method with argumentin text
file
fr=open("one.txt",'r')
fw=open("TWO.txt",'r')
nd=''
data=fr.read()
print("originaldata",data)
print("modified
data",data.replace('','@'))
for i in data:
if i=='':
nd+='#'
else:
nd=nd+i
print("Modified string",nd)
fw.write(nd)
fr.close()
fw.close()
#8 Count the number of occurrences of ‘the’ and ‘these’ andreplace with‘THE’
and ‘THESE”
#Count the number of 'the' and 'these'
f=open("one.txt",'r+')
data=f.read()
t1,t2=0,0
l=data.split()
New_l=''
for w in l:
if w=='file':
t1+=1
elif w=='My':
t2+=1
New_l+=w.upper()
else:
New_l+=w
New_l+=w
print("original filr:", data)
print("Modified file:",New_l)
print('no of file',t1)
print("My:",t2)
print("Total occurances:=",t1+t2)
===========
original filr: My first line of code
to enter data into a text file
we will do binary files later
Modified file:
MYMyfirstfirstlinelineofofcodeco
detotoenterenterdatadataintoin
toaatexttextfilewewewillwilldod
obinarybinaryfilesfileslaterlater
no of file 1
My: 1
Total occurances:= 2
BINARY FILES
#1 WAP to create a dictionary and write contents intoabinary file and display
the file contents andnumber of records
#2 WAP to searchfor a particular recordusing the key of a dictionary via binary
files
#3 WAP to update data storedina dictionary using binary files inpython
#4 WAP toread contents anddisplay number of bytes occupiedby it
#5 WAP to update data storedina dictionary using binary files inpython and
display the file
#6 WAP todelete records by user input froma dictionary using binary files
FUNCTIONS
#1 Function to add two numbers
INPUT OUTPUT
def add(a,b):
sum=a+b
return sum
a=int(input("Enter First Number"))
b=int(input("Enter Second Number"))
res=add(a,b)
print("Thesum of",a,"and",b,"is",res)
Enter FirstNumber2
Enter Second Number3
The sum of 2 and 3 is 5
#2
INPUT OUTPUT
def evenodd(x):
if (x%2==0):
print("even")
else:
print("Odd")
#driver code
evenodd(2)
evenodd(3)
even
Odd
#3 Identifying local x and global x
INPUT OUTPUT
x=300
def myfunc():
x=200
print("localx:",x)
myfunc()
print("globalx:",x)
local x: 200
global x: 300
#4 Using a global variable in nestedfunction
INPUT OUTPUT
def food():
x=20
def bar():
global x
x=25
print("Beforecalling bar:",x)
print("Calling bar now")
bar()
print("After calling bar:",x)
food()
print("xin main:",x)
Before calling bar: 20
Calling bar now
After calling bar: 20
x in main: 25
RANDOM MODULE
#1 Program to generate 5 random numbers
INPUT OUTPUT
import random
l=()
for i in range(5):
x=random.random()
y=int(x*10)
print(y)
4
6
2
0
9
#2 Program to generate 5 random numbers between 10 and 20
INPUT OUTPUT
import random
l=[]
for i in range(5):
x=int(random.random()*11)+10
print(x)
17
11
15
19
10
#3 Program to generate 5 random numbers between 50 to 100
INPUT OUTPUT
import random
for i in range(5):
x=random.randint(50,100)
print(x)
78
94
84
52
55
#4 Program to create a list of 5 random numbers
INPUT OUTPUT
import random
l=[]
for i in range(5):
x=random.random()
y=int(x*10)
l.append(y)
print("List of random values:",l)
List of random values: [4, 1, 3, 6,
2]
STACKS
#1 Stack implementation: perform pop and push operations on a list
of numbers
INPUT OUTPUT
def pstack():
s=[]
ch='y'
while ch=='y' or ch=='Y':
print("1. Push")
print("2. Pop")
print("3. Display")
c=int(input("enter choice.."))
if c==1:
ele=input("Enter element to add
to stack")
s.append(ele)
elif c==2:
if(s==[]):
print("Stack Empty")
else:
1. Push
2. Pop
3. Display
enter choice..3
Invalid input
continue...y
1. Push
2. Pop
3. Display
enter choice..1
Enter element to add to stack56
1. Push
2. Pop
3. Display
enter choice..3
56 -->
Invalid input
print("Deleted
element",s.pop())
elif c==3:
l=len(s)
for i in range(l-1,-1,-1):
print(s[i],"-->")
else:
print("Invalid input")
ch=input("continue...")
pstack()
continue...y
1. Push
2. Pop
3. Display
enter choice..2
Deleted element 56
1. Push
2. Pop
3. Display
enter choice..
#2 Program to display vowels present inauser input word using stacks
INPUT OUTPUT
v=['a','e','i','o','u']
w=input("Enter the word")
s=[]
for letter in w:
if letter in v:
if letter not in s:
s.append(letter)
print(s)
Enter the wordtable
['a', 'e']
Enter the wordhello
['e', 'o']
#3 REVERSING EACH WORD IN A STRING
INPUT OUTPUT
str1="Python Programming"
l1=str1.split()
str2=''
print("REVERSING EACH WORD IN A STRING
USING STRING(CONCATENATION)METHOD")
for i in l1:
for j in range(len(i)-1,-1,-1):
str2+=i[j]
str2+=''
print("Reversed string is",str2)
print("REVERSE EACH WORD USING STACK
IMPLEMENTATION")
revs=[]
for w in l1:
for j in range(len(w)-1,-1,-1):
revs.append(w[j])
revs.append('')
frevs=''.join(revs)
print("Original String:",str1)
print("Reversed String:",frevs)
REVERSING EACH WORD INA STRING
USING
STRING(CONCATENATION)METHOD
Reversed string is nohtyPgnimmargorP
REVERSE EACH WORD USING STACK
IMPLEMENTATION
Original String: Python Programming
Reversed String: nohtyPgnimmargorP
CSV FILES
#1 Writing ina CSV file
INPUT OUTPUT
import csv
f=open("St.csv","a+")
sw=csv.writer(f)
sw.writerow(["Adm
No","Name","Marks"])
for i in range(2):
print("Enter st record:")
r=int(input("Enter adm no"))
n=input("Enter name.")
m=float(input("Enter marks"))
sr=[r,n,m]
sw.writerow(sr)
f.close()
Enter st record:
Enter adm no27323
Enter name.Anushka
Enter marks98
Enter st record:
Enter adm no27324
Enter name.Vanya
Enter marks99
#2 Reading a CSV file
INPUT OUTPUT
#reading and diplay the contents from
the csv file
#import c-write
import csv
with open("St.csv","r",newline='rn')
as f:
cr=csv.reader(f)
print("Contents of csv file:")
for rec in cr:
print(rec)
Contents of the CSV File St.csv
[ ' Adm No ' , ' Name ', " Marks ' ]
[ ' 6573 ' , ' No ' , ' 98.0 ' ]
[ ' 6473 ' , ' Yes ' , ' 75.0 ' ]
[ ' 6476 ', ' Maybe ' , ‘ 68.0 ’ ]
[ ' 6374 ' , ' Sure ' , ' 99.0 ' ]
[ ' 6764 ' , ' IDK ' , ‘ 58.0 ' ]
[ ' Adm No ' , ' Name ' , " Marks ‘ ]
[ ' 6523 ' , ' Nu ' , ‘ 87.0 ‘ ]
[ ' 6912 ' , ' Hu ' , ' 57.0 ‘ ]
SQL
TABLE – 1
Q1. Create a Table “EmpN” with appropriate data types and primary key.
Q2. Insert the values to all the columns of the table.
Q3. Display the structure of the given table.
Q4. Display the employee details who have state id between 1 and 5.
Q5. Display the ID and Name of employees with names ending with “v”.
Q6. Display the details of the employees with Nation ID more than 4 or living in Delhi.
Q7. Display the maximum National ID and minimum State IDin table “EmpN”.
Q8. Display the total number of Employees in table “EmpN”.
Q9. If total number of employees is equal to the sum of top 8 employees. Then display the total
number of employees hired by the company.
Q10. Add a column of Work Experience to the table.
Q11. Display the average work experience of all the employees.
Q12. Increase the Work Experience of all the employees by 1 year.
Updated File
Q13. List Work Experience of employees in table EmpN.
Q14. Display the name of employees grouping them in Work Experience.
Q15. Display the details of the employees in the descending order of their State IDs.
TABLE – 2
Q1. Create a Table “Empl” with appropriate data types and primary key.
Q2. Insert the values to all the columns of the table.
Q3. Display the structure of the given table.
Q4. Display the employee details who are earning between 70000 and 80000.
Q5. Display the ID and Name of employees with names ending with “n”.
Q6. Display the details of the employees with age more than 27 or salary between 60000 and
70000.
Q7. Display the highest and lowest salary in table “Empl”.
Q8. Display the total number of Employees in table “Empl”.
Q9. Display the total money given by the company to the employees per month.
Q10. Display the average salary of all the employees.
Q11. Increase the salary of all the employees by 10%.
Updated Table
Q12. Add a column of Attendance% to the table.
Q13. List all ages of employees in table Empl.
Q14. Display the name of employees grouping them in ages.
Q15. Display the details of the employees in the descending order of their salaries.
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE

Mais conteúdo relacionado

Mais procurados

Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
Self-employed
 

Mais procurados (20)

Library Management Project (computer science) class 12
Library Management Project (computer science) class 12Library Management Project (computer science) class 12
Library Management Project (computer science) class 12
 
12th CBSE Computer Science Project
12th CBSE Computer Science Project12th CBSE Computer Science Project
12th CBSE Computer Science Project
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
 
Ip library management project
Ip library management projectIp library management project
Ip library management project
 
Computer Science Practical File class XII
Computer Science Practical File class XIIComputer Science Practical File class XII
Computer Science Practical File class XII
 
computer science with python project for class 12 cbse
computer science with python project for class 12 cbsecomputer science with python project for class 12 cbse
computer science with python project for class 12 cbse
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
 
Maths practical file (class 12)
Maths practical file (class 12)Maths practical file (class 12)
Maths practical file (class 12)
 
Computer Project for class 12 CBSE on school management
Computer Project for class 12 CBSE on school managementComputer Project for class 12 CBSE on school management
Computer Project for class 12 CBSE on school management
 
Physical Education Project | Class 12 | Practical
Physical Education Project | Class 12 | PracticalPhysical Education Project | Class 12 | Practical
Physical Education Project | Class 12 | Practical
 
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12THBANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
BANK MANAGEMENT INVESTIGATORY PROJECT CLASS 12TH
 
IP project for class 12 cbse
IP project for class 12 cbseIP project for class 12 cbse
IP project for class 12 cbse
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
 
Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)Computer science Project for class 11th and 12th(library management system)
Computer science Project for class 11th and 12th(library management system)
 
Computer project final for class 12 Students
Computer project final for class 12 StudentsComputer project final for class 12 Students
Computer project final for class 12 Students
 
Library Management Python, MySQL
Library Management Python, MySQLLibrary Management Python, MySQL
Library Management Python, MySQL
 
Computer science project on Online Banking System class 12
Computer science project on Online Banking System class 12Computer science project on Online Banking System class 12
Computer science project on Online Banking System class 12
 
Computer Science investigatory project class 12
Computer Science investigatory project class 12Computer Science investigatory project class 12
Computer Science investigatory project class 12
 
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
PHYSICAL EDUCATION PRACTICAL FILE ( Class 12th)
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
 

Semelhante a COMPUTER SCIENCE CLASS 12 PRACTICAL FILE

ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
jeyel85227
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
Blake0FxCampbelld
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
parthp5150s
 
Python Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdfPython Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdf
Rahul Jain
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
anzhong70
 

Semelhante a COMPUTER SCIENCE CLASS 12 PRACTICAL FILE (20)

ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
 
python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 
Practical File Grade 12.pdf
Practical File Grade 12.pdfPractical File Grade 12.pdf
Practical File Grade 12.pdf
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
Python Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdfPython Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdf
 
R basic programs
R basic programsR basic programs
R basic programs
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptx
 
PyLecture4 -Python Basics2-
PyLecture4 -Python Basics2-PyLecture4 -Python Basics2-
PyLecture4 -Python Basics2-
 
data structure and algorithm.pdf
data structure and algorithm.pdfdata structure and algorithm.pdf
data structure and algorithm.pdf
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
Python : Dictionaries
Python : DictionariesPython : Dictionaries
Python : Dictionaries
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

COMPUTER SCIENCE CLASS 12 PRACTICAL FILE

  • 1. TEXT FILES #1 Writing data intotext files using writelines with open("two.txt","w") as f: l=[] ch='y' x=0 while ch=='y': l=input("enter list values") f.writelines(l) ch=input("do you want to continue?") x+=1 print("file created successfully!!!with ",x,"records entered") enter list values"Suhani",89,"A" do you want to continue?y enter list values"Raunak",55,"C" do you want to continue?y enter list values"Cia",45,"D" do you want to continue?n file created successfully!!!with 3 records entered #2 Read() method intext files fr=open("one.txt","r") data=fr.read() print("Fileread successfully") print(data) fr.close() File read successfully My firstline of code to enter data into a text file we will do binary files later
  • 2. #3 Read() method withargument in text files fr=open("one.txt","r") data=fr.read(10) print("Fileread successfully") print(data) fr.close() File read successfully My firstl #4 Readline() methodintext files fr=open("one.txt",'r') data=fr.readline() print(data) print("line read successfully") fr.close() My firstline of code line read successfully
  • 3. #5 Using read() method in a Text file count number of consonants ,vowels ,digits and special characters f=open("one.txt",'r') data=f.read() sp,c,d,v=0,0,0,0 L=len(data) for i in data: print(i,end='') if i in ("aeiouAEIOU"): v+=1 elif i.isalpha(): c+=1 elif i.isdigit(): d+=1 My firstline of code to enter data into a text file we will do binary files later string: My firstline of code to enter data into a text file we will do binary files later Total no. of characters: 86 no. of consonents 39 vowels 26 digits: 0
  • 4. else: sp=L-(c+d+v) print("n string:", data) print("Totalno. of characters:",L) print("no. of consonents",c) print("vowels",v) print("digits:",d) print("specialnumbers",sp) special numbers 21
  • 5. #6 Using read() method in text file count the number of words in a text file (SPLIT FUNCTION) #counting the number of words in a text file f=open("one.txt",'r') data=f.read() l=data.split() w=len(l) print("contents of the file are n", data) print("Number of words:", w) Contents of the file are My firstline of code to enter data into a text file we will do binary files later Number of words: 18
  • 6. #7 Replace eachsignby ‘#’ sign, display the string and write intoa new file #Read method with argumentin text file fr=open("one.txt",'r') fw=open("TWO.txt",'r') nd='' data=fr.read() print("originaldata",data) print("modified data",data.replace('','@')) for i in data: if i=='': nd+='#' else: nd=nd+i print("Modified string",nd) fw.write(nd) fr.close() fw.close()
  • 7. #8 Count the number of occurrences of ‘the’ and ‘these’ andreplace with‘THE’ and ‘THESE” #Count the number of 'the' and 'these' f=open("one.txt",'r+') data=f.read() t1,t2=0,0 l=data.split() New_l='' for w in l: if w=='file': t1+=1 elif w=='My': t2+=1 New_l+=w.upper() else: New_l+=w New_l+=w print("original filr:", data) print("Modified file:",New_l) print('no of file',t1) print("My:",t2) print("Total occurances:=",t1+t2) =========== original filr: My first line of code to enter data into a text file we will do binary files later Modified file: MYMyfirstfirstlinelineofofcodeco detotoenterenterdatadataintoin toaatexttextfilewewewillwilldod obinarybinaryfilesfileslaterlater no of file 1 My: 1 Total occurances:= 2
  • 8. BINARY FILES #1 WAP to create a dictionary and write contents intoabinary file and display the file contents andnumber of records
  • 9. #2 WAP to searchfor a particular recordusing the key of a dictionary via binary files
  • 10. #3 WAP to update data storedina dictionary using binary files inpython
  • 11. #4 WAP toread contents anddisplay number of bytes occupiedby it
  • 12. #5 WAP to update data storedina dictionary using binary files inpython and display the file
  • 13. #6 WAP todelete records by user input froma dictionary using binary files
  • 14.
  • 15. FUNCTIONS #1 Function to add two numbers INPUT OUTPUT def add(a,b): sum=a+b return sum a=int(input("Enter First Number")) b=int(input("Enter Second Number")) res=add(a,b) print("Thesum of",a,"and",b,"is",res) Enter FirstNumber2 Enter Second Number3 The sum of 2 and 3 is 5 #2 INPUT OUTPUT def evenodd(x): if (x%2==0): print("even") else: print("Odd") #driver code evenodd(2) evenodd(3) even Odd
  • 16. #3 Identifying local x and global x INPUT OUTPUT x=300 def myfunc(): x=200 print("localx:",x) myfunc() print("globalx:",x) local x: 200 global x: 300 #4 Using a global variable in nestedfunction INPUT OUTPUT def food(): x=20 def bar(): global x x=25 print("Beforecalling bar:",x) print("Calling bar now") bar() print("After calling bar:",x) food() print("xin main:",x) Before calling bar: 20 Calling bar now After calling bar: 20 x in main: 25
  • 17. RANDOM MODULE #1 Program to generate 5 random numbers INPUT OUTPUT import random l=() for i in range(5): x=random.random() y=int(x*10) print(y) 4 6 2 0 9 #2 Program to generate 5 random numbers between 10 and 20 INPUT OUTPUT import random l=[] for i in range(5): x=int(random.random()*11)+10 print(x) 17 11 15 19 10
  • 18. #3 Program to generate 5 random numbers between 50 to 100 INPUT OUTPUT import random for i in range(5): x=random.randint(50,100) print(x) 78 94 84 52 55 #4 Program to create a list of 5 random numbers INPUT OUTPUT import random l=[] for i in range(5): x=random.random() y=int(x*10) l.append(y) print("List of random values:",l) List of random values: [4, 1, 3, 6, 2]
  • 19. STACKS #1 Stack implementation: perform pop and push operations on a list of numbers INPUT OUTPUT def pstack(): s=[] ch='y' while ch=='y' or ch=='Y': print("1. Push") print("2. Pop") print("3. Display") c=int(input("enter choice..")) if c==1: ele=input("Enter element to add to stack") s.append(ele) elif c==2: if(s==[]): print("Stack Empty") else: 1. Push 2. Pop 3. Display enter choice..3 Invalid input continue...y 1. Push 2. Pop 3. Display enter choice..1 Enter element to add to stack56 1. Push 2. Pop 3. Display enter choice..3 56 --> Invalid input
  • 20. print("Deleted element",s.pop()) elif c==3: l=len(s) for i in range(l-1,-1,-1): print(s[i],"-->") else: print("Invalid input") ch=input("continue...") pstack() continue...y 1. Push 2. Pop 3. Display enter choice..2 Deleted element 56 1. Push 2. Pop 3. Display enter choice.. #2 Program to display vowels present inauser input word using stacks INPUT OUTPUT v=['a','e','i','o','u'] w=input("Enter the word") s=[] for letter in w: if letter in v: if letter not in s: s.append(letter) print(s) Enter the wordtable ['a', 'e'] Enter the wordhello ['e', 'o']
  • 21. #3 REVERSING EACH WORD IN A STRING INPUT OUTPUT str1="Python Programming" l1=str1.split() str2='' print("REVERSING EACH WORD IN A STRING USING STRING(CONCATENATION)METHOD") for i in l1: for j in range(len(i)-1,-1,-1): str2+=i[j] str2+='' print("Reversed string is",str2) print("REVERSE EACH WORD USING STACK IMPLEMENTATION") revs=[] for w in l1: for j in range(len(w)-1,-1,-1): revs.append(w[j]) revs.append('') frevs=''.join(revs) print("Original String:",str1) print("Reversed String:",frevs) REVERSING EACH WORD INA STRING USING STRING(CONCATENATION)METHOD Reversed string is nohtyPgnimmargorP REVERSE EACH WORD USING STACK IMPLEMENTATION Original String: Python Programming Reversed String: nohtyPgnimmargorP
  • 22. CSV FILES #1 Writing ina CSV file INPUT OUTPUT import csv f=open("St.csv","a+") sw=csv.writer(f) sw.writerow(["Adm No","Name","Marks"]) for i in range(2): print("Enter st record:") r=int(input("Enter adm no")) n=input("Enter name.") m=float(input("Enter marks")) sr=[r,n,m] sw.writerow(sr) f.close() Enter st record: Enter adm no27323 Enter name.Anushka Enter marks98 Enter st record: Enter adm no27324 Enter name.Vanya Enter marks99 #2 Reading a CSV file INPUT OUTPUT #reading and diplay the contents from the csv file #import c-write import csv with open("St.csv","r",newline='rn') as f: cr=csv.reader(f) print("Contents of csv file:") for rec in cr: print(rec) Contents of the CSV File St.csv [ ' Adm No ' , ' Name ', " Marks ' ] [ ' 6573 ' , ' No ' , ' 98.0 ' ] [ ' 6473 ' , ' Yes ' , ' 75.0 ' ] [ ' 6476 ', ' Maybe ' , ‘ 68.0 ’ ] [ ' 6374 ' , ' Sure ' , ' 99.0 ' ] [ ' 6764 ' , ' IDK ' , ‘ 58.0 ' ] [ ' Adm No ' , ' Name ' , " Marks ‘ ] [ ' 6523 ' , ' Nu ' , ‘ 87.0 ‘ ] [ ' 6912 ' , ' Hu ' , ' 57.0 ‘ ]
  • 23. SQL TABLE – 1 Q1. Create a Table “EmpN” with appropriate data types and primary key. Q2. Insert the values to all the columns of the table.
  • 24. Q3. Display the structure of the given table. Q4. Display the employee details who have state id between 1 and 5. Q5. Display the ID and Name of employees with names ending with “v”. Q6. Display the details of the employees with Nation ID more than 4 or living in Delhi.
  • 25. Q7. Display the maximum National ID and minimum State IDin table “EmpN”. Q8. Display the total number of Employees in table “EmpN”. Q9. If total number of employees is equal to the sum of top 8 employees. Then display the total number of employees hired by the company.
  • 26. Q10. Add a column of Work Experience to the table. Q11. Display the average work experience of all the employees. Q12. Increase the Work Experience of all the employees by 1 year. Updated File
  • 27. Q13. List Work Experience of employees in table EmpN. Q14. Display the name of employees grouping them in Work Experience. Q15. Display the details of the employees in the descending order of their State IDs.
  • 28. TABLE – 2 Q1. Create a Table “Empl” with appropriate data types and primary key. Q2. Insert the values to all the columns of the table.
  • 29. Q3. Display the structure of the given table. Q4. Display the employee details who are earning between 70000 and 80000. Q5. Display the ID and Name of employees with names ending with “n”.
  • 30. Q6. Display the details of the employees with age more than 27 or salary between 60000 and 70000. Q7. Display the highest and lowest salary in table “Empl”. Q8. Display the total number of Employees in table “Empl”. Q9. Display the total money given by the company to the employees per month.
  • 31. Q10. Display the average salary of all the employees. Q11. Increase the salary of all the employees by 10%. Updated Table
  • 32. Q12. Add a column of Attendance% to the table. Q13. List all ages of employees in table Empl.
  • 33. Q14. Display the name of employees grouping them in ages. Q15. Display the details of the employees in the descending order of their salaries.