Computer Science Class XII Python File Handling Test Series Part 5
Q1. Reading and writing opeation can be done after close() function(T/F)
Q2. f = open("test.txt", "r")
Write the output f the following
1. print(f.name)
2. print(f.mode)
3. print(f.closed)
4. prin(f.readable())
Q3. Write a program to accept five numbers from the user and write in a file "num.txt"
Q4. What type of error is shown by the following line of code.
f.write(3)
where f is file handle associated with text file named "try.txt"
Q5. write() function takes integer argument. (T/F)
Q6. Write a proram to accept 10 numbers from the user. if the number is even than write that number in "even.txt", otherwise, write in file "odd.txt"
Q7. Write a program to create a list of five subjects and write them in a file named "subject.txt"
Q8. What type of error is shown by the following line of code?
f.write(try)
Where f is file object and try is a an object of list type.
Q9. What type of error is shown by the following line of code?
f.writeline(try)
Where f is file object and try is a an object of list type.
Q10. writelines() method does not add any EOL character to the end of String. (T/F)
SOLUTIONS
Q1. Reading and writing opeation can be done after close() function(T/F)
Ans. False
Q2. f = open("test.txt", "r")
Write the output f the following
1. print(f.name)
2. print(f.mode)
3. print(f.closed)
4. prin(f.readable())
Ans.
1. test.txt
2. r
3. False
4. True
Q3. Write a program to accept five numbers from the user and write in a file "num.txt"
Ans.
Q4. What type of error is shown by the following line of code.
f.write(3)
where f is file handle associated with text file named "try.txt"
Ans. TypeError
Q5. write() function takes integer argument. (T/F)
Ans. False
Q6. Write a proram to accept 10 numbers from the user. if the number is even than write that number in "even.txt", otherwise, write in file "odd.txt"
Ans.
Q7. Write a program to create a list of five subjects and write them in a file named "subject.txt"
Q8. What type of error is shown by the following line of code?
f.write(try)
Where f is file object and try is a an object of list type.
Ans. TypeError: write() argument must be str, not list
Q9. What type of error is shown by the following line of code?
f.writeline(try)
Where f is file object and try is a an object of list type.
Ans. AttributeError
Q10. writelines() method does not add any EOL character to the end of String. (T/F)
Ans. True
No comments:
Post a Comment