PYTHON
Files
Fill in the blanks
1.Write a mode for file read 'r'
2. Write a mode for file write 'w'
3. Write a mode for file append 'a'
4.Write a command for changing directory chdir
5.Write a command for making a new directory mkdir
6.Write a command for present working directory getcwd()
Answer the following questions
(4 marks)
1.Write a program for file writing.
jkfile=open("biodata.txt","w")
ch='y'
while ch=='y':
x=input("enter a name...")
jkfile.write(x+"\n")
ch=input("continue..[y/n]:")
jkfile.close()
2.Write a program for file Reading.
jkfile=open("biodata.txt","r")
for i in jkfile:
print(len(i))
print(i)
jkfile.close()
3.Write a program for file writing and file Reading
Tfile=open("hai.txt","w")
Tfile.write("hai\n")
Tfile.write("hello\n")
Tfile.write("how
are you")
Tfile.close()
print("\n"*50)
Tfile=open("hai.txt","r")
for
line in Tfile:
print(line)
Tfile.close()
No comments:
Post a Comment