0% found this document useful (0 votes)
40 views12 pages

Report File - XII - LAB Programs 1 - 12 - 1

The document describes 12 programming exercises involving text file manipulation and user-defined functions in Python. For each exercise: 1) The aim is described to write Python functions to perform tasks like counting word occurrences, vowels/consonants, lines starting with letters, copying/replacing text, finding unique words, and more. 2) The source code provides implementations of the functions to achieve the aims. 3) Each exercise is described as being successfully completed and executed.

Uploaded by

Arjun's clan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views12 pages

Report File - XII - LAB Programs 1 - 12 - 1

The document describes 12 programming exercises involving text file manipulation and user-defined functions in Python. For each exercise: 1) The aim is described to write Python functions to perform tasks like counting word occurrences, vowels/consonants, lines starting with letters, copying/replacing text, finding unique words, and more. 2) The source code provides implementations of the functions to achieve the aims. 3) Each exercise is described as being successfully completed and executed.

Uploaded by

Arjun's clan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

EX.NO.

01 User Defined Functions to Manipulate Strings


Separate URL and Replace String
AIM:

A) To write a function SEP_URL(url) in python to accept an URL of a web page as


argument and return the different parts of it as multiple values.
B) To write a function Replace_Str(S1) in python, that accepts the given text as argument
and replace the word ‘sad’ with ‘happy’ in the first 2 occurrences and replace ‘news’
with ‘information’ only in the first occurrence of the text.
Input Text: I have just received some very sad news. This music always makes me sad. We
all felt sad about his death. The news was devastating to all of us.
SOURCE CODE:
A)

B)

RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the String was successfully completed and executed successfully.
EX.NO.02 User Defined Functions to Manipulate Strings
Accept String with All Vowels & Display Common words from 2strings
AIM:
A) To write a function VowelStr(data) in python, that accepts a string as argument and to
display “Input Data is accepted” if the string contains all the vowels. If not, display
“Input Data not accepted”.
B) To write a function COMMON(S1,S2) in python to accept 2 strings as arguments and
to find the common words in both the strings.
SOURCE CODE:
A)

B)

RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the String was successfully completed and executed successfully.
EX.NO: 03 User Defined Functions to manipulate List
Store Indices of Non Zero elements &Double the Odd values
AIM:
A) To write a function INDEX_LIST(L) in python, where L is the list of elements passed
as argument to thefunction. The function returns another list named ‘IndexList’ that stores
the indices of all Non-Zero Elements of L.
For example: If L contains [12,4,0,11,0,56]. The IndexList will have-[0,1,3,5]
B) To write a function DoubletheOdd( ) in python to add and display double the sum of
odd values from the list Nums.
For example : If the Nums contains [25,24,35,20,32,41] .
The function should display Double of Odd Sum: 202
SOURCE CODE:
A)

B)

RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the List was successfully completed and executed successfully.
EX.NO: 04 User Defined Functions to manipulate List
Store Indices of 4 lettered words &Swap adjacent elements
AIM:
A) To write a function lenFOURword(L) in python , where L is the list of elements
(list of words) passed as an argument to the function. The function returns another list
named ‘indexList’ that stores the indices of all four lettered word of L.
B) To write a function SwapAdjacent(nums) in python, that accepts a list as
argument and interchanges the adjacent elements and prints both the original list and
the modified list.

SOURCE CODE:
A)

B)

RESULT : Thus the python program with user defined functions to perform the
above mentioned tasks in the List was successfully completed and executed
successfully.
EX.NO:05 User Defined Functions to Manipulate List
Find the Longest Word and Shifting the elements to left

AIM:
A) To write a function Longest_Word(Words_list)in python that accepts a list of words as an
argument and returns the longest word from the list with its length.
B) To write a function Lshift(L,N) in python, where L is the list of elements passed as an
argument to the function. The function shifts all the elements by N places to the left and
then print it.For example: If L contains [9,4,0,3,11,56] and N=2
The function will print - [0,3,11,56,9,4]

SOURCE CODE:

A)

B)

RESULT : Thus the python program with user defined functions to perform the above
mentioned tasks in the List was successfully completed and executed successfully.
EX.NO:06 “Guess the Number Game” using random module
AIM:
To write a python program to implement
“Guess the NumberGame” using random module.

SOURCE CODE:

RESULT :Thus the python program to implement “Guess the number game” using random
module was executed successfully.
EX.NO.07 Sorting List Of Tuples By Second Item &
Manipulate Student Marks In Nested Tuples
AIM:
A) To write a function Sort_Tuple(tup) in python to sort a list of tuples by the second
item.
B) To write a program to create a nested tuple to store student marks and a function
calc(m) to display the total and average of their marks.
SOURCE CODE:
A)

B)
SOURCE CODE:
A)

RESULT: Thus a python program with user defined functions to manipulate the marks
in nested tuples and sort the elements in tuples has been completed and executed
successfully.
EX.NO.08 Manipulating Dictionary using Functions
AIM: To write a menu driven python program with user defined functions to manipulate
customer details in a dictionary using function.
SOURCE CODE:

RESULT : Thus the menu driven python program with user defined functions to manipulate
the customer details dictionary has been completed and executed successfully.
EX.NO.09 TEXT FILES IN PYTHON
Count the occurrences of word & Count number of vowels and consonants
AIM:
A) To write a function RainCount() in Python, which should read the content of a text
file ‘TESTFILE.TXT’ and then count and display the count of occurrence of word
RAIN (case-insensitive) in the file.
B) To write a function Vowels() in Python, which should read the content of a text
file ‘TESTFILE.TXT’ and then count and display the number of vowels and
consonants present in the file.
SOURCE CODE:
A)

B)

RESULT : Thus a Python program to read a text file and to count and display the number of
occurrences of a word and number of vowels and consonants in the file has been completed
and executed successfully.
EX.NO.10 TEXT FILES IN PYTHON
Count the lines starts with I/T & Display the lines with exactly 6 words
AIM:
A) To write a function Countlines() in Python to read a text file ‘Poem.txt’ and count and
display the number of lines starts with ‘A’ / ‘B’ separately.
B) To write a function ShowLines() in Python, that would read the contents of a text file
‘Poem.txt’ and display only those lines which contains exactly 6 words in it.
SOURCE CODE:
A)

B)

RESULT : Thus a Python program to read a text file and to count the number of lines starts
with A/B and display the lines contain 6 words has been completed and executed
successfully.
EX.NO.11 TEXT FILES IN PYTHON
Copying lines to a new file & Replacing the ‘-‘ sign with a blankspace

AIM:

A) Write a function Filter(oldfile,newfile) in Python that would read the contents of the file
‘source.txt’ and copy only those lines which does not contain ‘@’ sign in it to a new text file
‘target.txt’.
B) Write a function Replace() in Python to read the text file ‘Source.txt’ and to replace the ‘-‘ sign
with blankspace in all the occurrences.

SOURCE CODE:

A)

B)

RESULT : Thus a Python program to read a text file and to copy the lines to a new file and
replacing ‘’ sign with a blankspace has been completed and executed successfully.
EX.NO.12 TEXT FILES IN PYTHON
Remove duplicate lines from the file & Display unique words present in the file
AIM:
A) Write a function RemoveLines() in Python that would read the contents of the file ‘Poem.txt’
and remove the duplicate lines from the file.
B) Write a function UniqueWord() in Python to read the text file ‘Stars.txt’ and to display the
unique words from the file.

SOURCE CODE:

A)

B)

RESULT : Thus a Python program to read a text file and to remove the duplicate lines from
the file and to display the unique words stored in the filehas been completed and executed
successfully.

You might also like