The document outlines a series of Python programming tasks, including reading text files, counting characters, integrating with MySQL, and performing various mathematical operations. Each task is described with specific objectives, such as displaying vowels and consonants, generating random numbers, and implementing stack operations. The document also includes sample code snippets and expected outputs for each task.
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 ratings0% found this document useful (0 votes)
30 views20 pages
20 Programs Python
The document outlines a series of Python programming tasks, including reading text files, counting characters, integrating with MySQL, and performing various mathematical operations. Each task is described with specific objectives, such as displaying vowels and consonants, generating random numbers, and implementing stack operations. The document also includes sample code snippets and expected outputs for each task.
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/ 20
1+ CREATING A PYTHON PROGRAM TO READ A TEXT FILE AND DISPLAY THE NUMBER OF
VOWELSICONSONANTS/LOWER CASE/ UPPER CASE CHARACTERS.
2-CREATING A PYTHON PROGRAM TO READ A TEXT FILE LINE BY LINE AND
DISPLAY EACH WORD SEPARATED BY '#”
3-CREATING PYTHON PROGRAM TO DISPLAY SHORT WORDS FROM A
TEXT FILE
4-CREATING A PYTHON PROGRAM TO COPY PARTICULAR LINES OF A TEXT FILE INTO AN
ANOTHER TEXT FILE
5- CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(CREATING DATABASE AND TABLE)
6- CREATING A PYTHON PROGRAM TO IMPLEMENT RETURNING VALUE(S)
FROM FUNCTION
7-CREATING A PYTHON PROGRAM TO IMPLEMENT MATHEMATICAL
FUNCTIONS:
8- CREATING A PYTHON PROGRAM TO GENERATE RANDOM NUMBER
BETWEEN 1TO6
9- CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (INSERTING
RECORDS AND DISPLAYING RECORDS)
10- CREATING A MENU DRIVEN PROGRAM TO FIND FACTORIAL AND SUM OF LIST OF
NUMBERS USING FUNCTION.
11- CREATING A MENU DRIVEN PROGRAM TO PERFORM ARITHMETIC
OPERATIONS
12- CREATING A PYTHON PROGRAM TO DISPLAY FIBONACCI SERIES
13+ CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (SEARCHING AND
DISPLAYING RECORDS)
14- CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(UPDATING RECORDS)
15- CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS
FILE
16- CREATING A PYTHON PROGRAM TO IMPLEMENT STACK
OPERATIONS(Dictionary)
17- CREATING A PYTHON PROGRAM TO CREATE AND SEARCH EMPLOYEE'S RECORD
IN CSV FILE
18+ CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY
RECORDS IN BINARY FILEee Coen UP ars eee Etat
NC me OR eee os ee ee Cas oe
Ni
DN Eee CL a a eRe occ ena
Vowels/ Consonants/ Lowercase / Uppercase/characters in the file.
RYT ot kae ly
feopen(*Story.txt",'r')
Contente=£.read()
Vowel s=0
lConsonants=0
ch in ‘aeiouAztou
Vowel s=Vowels+1
ch in ‘bedfgh}klanpqrstvwxy2BCDFGHIKLMNPORSTVWXY2
Consonants=Consonants+1
ch.ialower()
Lower_case=Lower_case+1
ch.isupper () :
Upper_case-Upper_caset+1
£.close()
print("The total numbers of vowels in the file:”,Vowels)
print ("The total numbers of consonants in the file:”,Consonants)}
print("the total numbers of uppercase in the file:",Upper_case)
print("The total numbers of lowercase in the file:",Lower_case)
ieee
See nn eee ects CCR Meee
etessoan
Po
Aron ae a
Like a Joy on the heart of a sorrow.
[The sunset hangs on a cloud.
‘of vowels in the file: 20
of consonants in the file: 29
of uppercase in the file: 3
of lowercase in the filePEC Et cee Ae
fee srs Bae
SOURCE CODE:
f=open("Story. txt", 'r')
Contents=£. readlines ()
for line in Contents:
words=line. split ()
i in words:
print (i+'#' ,end-
print ("")
f.close()
Poona
ATU OE ae eee ee eee Cee Ce RS Rr Ty
tte ina
Peel aa
ans
Like a Joy on the heart of a sorrow.
‘The sunset hangs on a cloud.CREATING PYTHON PROGRAM TO DISPLAY SHORT WORDS FROM A TEXT FILE
‘To Write a method Disp() in Python, to read the lines from poem.txt and display those
ROE Ee one SLC tort
Perec
print("The follwoing words are less than 5 characters
iin Ws
Jen{i}')
nosint (input ("Enter RSL1.No of student to search:"))
‘founded
try
while true
Sepickle. load (F)
Sf 8[0}=eno.
PEAnE ("The searched Roll.Mo is found and Details are:
foundel
except
F.close()
££ founde=o.
Print ("The Searched Roli.No is net found")
fain Program
Create()
Search()
”
=
Enter roll number:1
Enter Name:Arun
Do you want to add another student detail(y/n) :y
Enter roll number:2
Enter Name:Bala
Do you want to add another student detail(y/n) :y
Enter roll numbe:
Enter Name:Charan
Do you want to add another student detail (y/n!
Enter roll number:4
Enter Name:Dinesh
Do you want to add another student detail(y/n) :y
Enter roll number:5
Enter Name:Divya
Do you want to add another student detail(y/n) :n
Enter Roll.No of student to search:3
The searched Roll.No is found and Details are: [3, 'Charan']CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(Dictlonary)
ri
coer
cee
h separate user-defined functions to perform the fallo
id
(W To Create a function Push(Stk,D) Where Stack is an empty listand D is Dictionary of Items.
from this Dictionary Push the keys (name of the student) into a stack, where
the corresponding value (marks) is greater than 70.
(ii) To Create a Function Pop( Stk) , where Stk is a Stack implemented by a list of student
names. The function returns the items deleted from the stack.
CO Rea ered ee eee aC
etesor ca
DyArun Jintfnput{ Eater the Mark of Arun)
DyAwu intiaput| Eater the Mark of Ana)
D[Vianai}mintlenpuet Pater the Mark of Via)
DiPriys Pint{input{ Eater the Mark of Prive)
Df Mano eiatlinpull Eater the Mark of Mane:a
def Create()
eopen("Eap.cev", 'a newlinen’*)
Weesv.writer(F)
y
Ronint (anput ("Enter Baployee Wumber:“))
Manewinput ("Enter Employes Mane:")
Sainflont (Anput("Enter Employee Salazy:"))
=o, Name, Sal}
Wowesterow(L)
opt=input ("De you want to contimue(y/a) ?:")
.
F.clos
Jeet seazen(y
Yeopen ("imp cav", ‘er! ,newlines\e\n')
noaint apse ("Enter imployes tuber to search"))
founded
sowncov. reader (P)
ioe aaa" row!
{f data 0}mmste (no)
rine (\numployee Deatiis are:*)
print >
Deine (’mame’*jaata(a])
Deine ("salary!*,aata(2!
F.close()
Jaman Program
lereate)
Jsearen
Enter Employee Number:1
Enter Employee Name: Anand
Enter Employee Salary:23000
Do you want to continue (y/n) ?:y
Enter Employee Number :2
Enter Employee Name:Akash
Enter Employee Salary:25000
Do you want to continue (y/n)?:y
Enter Employee Number :3
Enter Employee Nane:Balu
Enter Employee Salary:27000
Do you want to continue (y/n)?:y
Enter Employee Number:4
Enter Employee Nane:Bavya
Entex Employee Salary:29000
Do you want to continue (y/n) ?:¥
Enter Employee Number:5
Enter Employee Name:Mano}
Enter Employee Salary:35000
Do you want to continue (y/n)?:n
Enter Employee number to search:3
Employee Deatils are
Mame: Balu
Salary: 2700.0oO ee Oe ea US)
Pea
AM:
See Ce Oe ee ee ee
and update/modify the mark for a given roll number
ele ta la
Lmport plekte
aor Createy)?
eopen ("Marks .dat*, ‘ab")
opte'y
while optae'y
RoLl_Nowint (input (‘Enter roll number")
Mamesinput ("Enter Mame: ")
Mark=int (input ("Enter Mazke:*))
Le[Roll Ho, Wane Mark]
Pickle. dump (L, 7)
‘Opt=input ("bo you want to add another student detaili(y/n) :*)
F.close()
ot Updated)
Proper ("unre dat, xb")
novint (snput (“Eater Student Roll.to to modify marks:))
founded
try:
Poo=r-telLo
Sopeenle.losair)
SP s[0]=n00.
Eint ("The searched Roli.Mo ie found and Detaiie are:",s)
Sl2}mine (input ("ancer New Mark to be upaate:))
F.seek (Pos)
piskle-duep (6.7)
Fiseek (Pos) roving the file pointer again beginning of the current record
Eine ("Mark wpdated Successfully and Details are:";8)
Feetoseo,
A foundeno:
Print ("The Searched RoliWo 1s not found”)
ain Program
studen 1(y/n) zy
x student detail (y/n) :y
Enter Student Roll.
11
to modify marks:3
found and Details are
t2:470
ind Details areBIBLIOGRAPHY
www.quora.com
www.slideshare.net
Class 12 Computer Science by
Sumita Arora