0% found this document useful (0 votes)
4 views4 pages

7

The document outlines a Python program that creates a text file named 'sentence.txt' and includes functions to categorize characters into lowercase, uppercase, and digits, as well as to identify palindromes. It specifies the creation of three output files: 'lower.txt', 'upper.txt', and 'digit.txt', along with a file for palindromes named 'palindrome.txt'. The program also includes a display function to print the contents of these files.

Uploaded by

devkniju
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)
4 views4 pages

7

The document outlines a Python program that creates a text file named 'sentence.txt' and includes functions to categorize characters into lowercase, uppercase, and digits, as well as to identify palindromes. It specifies the creation of three output files: 'lower.txt', 'upper.txt', and 'digit.txt', along with a file for palindromes named 'palindrome.txt'. The program also includes a display function to print the contents of these files.

Uploaded by

devkniju
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/ 4

DATE:01-07-2025

PRACTICAL OBJECTIVE & SOLUTIONS


NO.
Write a program in python to create a text file “sentence.txt” and functions
as given below:
7  moveCharacters( ) -to create three files “lower.txt” which contains
all the lowercase letters and “upper.txt” which contains all the
uppercase letters and “digit.txt” which contains all digits from the
above mentioned text file.
 palindrome( ) -to store all palindrome words to a new file
“palindrome.txt”.

Read and display upper.txt, digit.txt and palindrome.txt.

def create():
f=open("sentence.txt","w")
n=int(input("Enter number of lines:"))
for i in range(n):
y=input("Enter line:")
f.write(y+"\n")

f.close()
def moveCharacters( ):
f=open("sentence.txt","r")
#to clear old data
a=open("lower.txt","w")
SOURCE b=open("upper.txt","w")
CODE: c=open("digit.txt","w")
a.close()
b.close()
c.close()

a= open('lower.txt','a')
b= open('uppper.txt','a')
c= open('digit.txt','a')
r= f.readlines()
f.close()

for i in r:
for j in i:
if j.islower():
a.write(j+ ' ')
elif j.isupper():
b.write(j+' ')
elif j.isdigit():
c.write(j+' ')
a.close()
b.close()
c.close()

def palindrome( ):
f = open('sentence.txt','r')
p = open('palindrome.txt','w')
w = f.read().split()
f.close()
#checking if a word is palindrome or not
for i in w:
if i == i[::-1]:
p.write(i+' ')
p.close()

def display():
print()
a= open('lower.txt','r')
b= open('uppper.txt','r')
c= open('digit.txt','r')
p = open('palindrome.txt','r')

print("Letters in lower.txt")
print("- - - - - - - - - - - ")
print(a.read())
print()

print("Letters in upper.txt")
print("- - - - - - - - - - - ")
print(b.read())
print()

print("Letters in digit.txt")
print("- - - - - - - - - - - ")
print(c.read())
print()

print("Letters in palindrome.txt")
print("- - - - - - - - - - - - ")
print(p.read())
print()

a.close()
b.close()
c.close()
p.close()

def main():
create()
moveCharacters()
palindrome()
display()

main()

Enter number of lines:5


Enter line:Class 12th D
Enter line:Hallelujah
Enter line:malayalam 123
Enter line:John jacobs
Enter line:king kong

Letters in lower.txt
-----------
lassthallelujahmalayalamohnjacobskingkong

Letters in upper.txt
-----------
CDHJ

OUTPUT: Letters in digit.txt


-----------
12123

Letters in palindrome.txt
------------
D malayalam

You might also like