Fr1.
py
"""
Created on Mon Nov 9 [Link] 2020
@author: Hp
"""
try:
f=open("[Link]","r")
s=[Link]()
print("The content of a file:",s)
except Exception:
print("Error")
[Link]
"""
Python program to read a line of text from keyboard and
write it to a file inputted by the user.
"""
x=input("Enter a file name:")
try:
k=open(x,"w")
s=input("Enter a line of text")
[Link](s)
except Exception:
print("Error")
finally:
[Link]()
[Link]
"""
Python program to read each line from a file biodata
and count number of lines using readline() function
"""
count=0
try:
h=open("[Link]","r")
while True:
k=[Link]()
if k:
print(k)
count=count+1
else:
break
except Exception:
print("Error")
else:
print("Total number of lines:",count)
[Link]
"""
Python program to read each line from a file biodata
and count number of lines using readlines() function
"""
count=0
try:
h=open("[Link]","r")
l=[Link]()
print(l)
for k in l:
print(k)
count=count+1
except Exception:
print("Error")
else:
print("Total number of lines:",count)
[Link]
"""
Python program to read each line from a file biodata
and count number of lines using readlines() function
"""
count=0
try:
h=open("[Link]","r")
for i in h:
print(i)
count=count+1
except Exception:
print("Error")
else:
print("Total number of lines:",count)
[Link]
"""
Python program to accept string from user until user press @ symbol.
Write the inputted string to a file input by the user
"""
s=input("Enter a file name:")
print("Enter a string and exit by pressing @ symbol")
try:
f=open(s,"w")
m=''
while m!='@':
m=input("Enter a string:")
if m!='@':
[Link](m+'\n')
except Exception:
print("Error")
finally:
[Link]()
[Link]
"""
Python program to count number of lines words
and characters from a given text file
"""
lc=0
wc=0
cc=0
try:
p=open("[Link]","r")
for j in p:
print(j)
lc=lc+1
wr=[Link](' ')
wc=wc+len(wr)
cc=cc+len(j)
print("Number of lines:",lc)
print("Number of words:",wc)
print("Number of characters:",cc)
except Exception:
print("Error")
finally:
[Link]()
[Link]
"""
Python program to read a lines from text file
that starts with from and print it on screen
"""
try:
m=open("[Link]","r")
while True:
k=[Link]()
if k:
if [Link]("from"):
print([Link]())
else:
break
except Exception:
print("Error")
finally:
[Link]()
[Link]
"""
Python program that generates the factorial of all integers from 1 to 10
and stores them in a file called [Link]
"""
import math
try:
f=open("[Link]","w")
for i in range(1,11):
[Link]("The factorial of {} is {}\n".format(i,[Link](i)))
except Exception:
print("Error")
finally:
[Link]()
finally:
[Link]()
[Link]()
[Link]()
10
"""
Python program to read the numbers stored in a file [Link].
Check the number is even or odd. If even
write it to a file [Link] otherwise write it to a file [Link]
"""
f=open("[Link]")
f1=open("[Link]","w")
f2=open("[Link]","w")
while True:
k=[Link]()
if k:
if int(k)%2==0:
[Link](k+'\n')
else:
[Link](k+'\n')
else:
break
[Link]()
[Link]()
[Link]()
11.
"""
Python program to copy an image file into another file
"""
f=open("D:\[Link]","rb")
f1=open("[Link]","wb")
b=[Link]()
[Link](b)
[Link]()
[Link]()