Professional Documents
Culture Documents
txt” in cnt_digits=0
python and ask the user to write a for ch in data:
single line of text by user input. if ch.islower():
cnt_lcase+=1
def program1(): if ch.isupper():
f = open("intro.txt","w") cnt_ucase+=1
text=input("Enter the text:") if ch.isdigit():
f.write(text) cnt_digits+=1
f.close() print("Total Number of Upper
program1() Case letters are:",cnt_ucase)
print("Total Number of Lower
[2] Create a text file “MyFile.txt” Case letters are:",cnt_lcase)
in python and ask the user to write print("Total Number of digits
separate 3 lines with three input
are:",cnt_digits)
statements from the user.
program4()
def program2():
[5] Write a program to count a total
f = open("MyFile.txt","w")
number of lines and count the total
line1=input("Enter the text:")
number of lines starting with ‘A’,
line2=input("Enter the text:")
‘B’, and ‘C’. (Consider the
line3=input("Enter the text:")
merge.txt file)
new_line="\n"
def program5():
f.write(line1)
with open("merge.txt","r") as
f.write(new_line)
f1:
f.write(line2)
data=f1.readlines()
f.write(new_line)
cnt_lines=0
f.write(line3)
cnt_A=0
f.write(new_line)
cnt_B=0
f.close()
cnt_C=0
program2()
for lines in data:
cnt_lines+=1
[3] Write a program to read the
contents of both the files created if lines[0]=='A':
in the above programs and merge the cnt_A+=1
contents into “merge.txt”. Avoid if lines[0]=='B':
using the close() function to close cnt_B+=1
the files. if lines[0]=='C':
def program3(): cnt_C+=1
with open("MyFile.txt","r") as
print("Total Number of lines
f1:
data=f1.read() are:",cnt_lines)
with open("intro.txt","r") as print("Total Number of lines
f2: strating with A are:",cnt_A)
data1=f2.read() print("Total Number of lines
with open("merge.txt","w") as strating with B are:",cnt_B)
f3:
print("Total Number of lines
f3.write(data)
strating with C are:",cnt_C)
f3.write(data1)
program3() program5()