CBSE COMPUTER SCIENCE
Открыть в Telegram
QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1
Больше549
Подписчики
Нет данных24 часа
Нет данных7 дней
Нет данных30 день
Архив постов
Python and MySql Download from : https://drive.google.com/drive/folders/1VvsQQB_L079eNF9UTDQ1TvDetvJUUBMG?usp=sharing
31. What will be the output of the following code snippet? (2M)
import sys
print ('Enter your name: ',)
name = ''
while True:
c = sys.stdin.read(1)
if c == '\n':
break
name = name + c
print ('Entered name is:', name)
#Assuming that input given by user is :Our Country
32. What will be the output of the following code snippet? (2M)
with open("hello.txt", "w") as f:
f.write("Hello World how are you today")
with open('hello.txt', 'r') as f:
data = f.readlines()
for line in data:
words = line.split()
print (words)
f.close()
33. What will be the output of the following code snippet? (2M)
f = open("data.txt", "w+")
txt = "This is 1st line\n"
f.writelines( txt )
seq = " This is 2nd line\nThis is 3rd line"
f.seek(0, 2)
f.writelines( seq )
myList = []
for line in f:
myList.append(line)
print(myList)
f.close()
34. What will be the output of the following code snippet? (2M)
f = open("data.txt", "r")
txt = "This is 1st line\n"
f.writelines( txt )
f.seek(0,0)
line = f.readlines()
print ("Read Line: %s" % (line))
f.close()
35. What will be the output of the following code snippet? (2M)
try:
f = open("testfile", "r")
f.write("This is the test file for exception handling!!")
except IOError:
print ("Error: could not find a file or read data")
else:
print ("content is written in the file successfully")
36. Write a python program to copy the contents of a file to another file using main()? (3M)
37. Write a python program to create a copy of the file “report.txt” named as “file1.txt”, which should convert the first letter of the file to uppercase using a function “capitalize_function”. (3M)
38. Consider STACK=[‘a’,’b’,’c’,’d’]. Write the STACK content after each operations: (3M)
a) STACK.pop( )
b) STACK.append(‘e’)
c) STACK.append(‘f’)
39. Write a python program to perform insert in a queue containing books details(bno,bname) (3M)
40. Write a python program to perform deletion from a queue containing books
details(bno,bname). (3M)
Output:
Friends are honest
, Friends
are best !
22. Write a function cust_data() to ask user to enter their names and age to store data in
customer.txt file. (2M)
OUTPUT
def cust_data():
name = input("Enter customer name:")
age=int(input("Enter customer age:"))
data = str([name,age])
f = open("customer.txt","w")
f.write(data)
f.close()
23. What are the two built-in functions to read a line of text from standard input, which is by default the keyboard? (2M)
a) Raw_input
b) Input
c) Read
d) Scanner
Answer. A and B
24. What will be the output of the following code snippet? (2M)
fo = open("myfile.txt", "w+")
print ("Name of the file: ", fo.name)
# Assuming that the file contains these lines
# TechBeamers
# Hello Viewers!!
seq="TechBeamers\nHello Viewers!!"
fo.writelines(seq )
fo.seek(0,0)
for line in fo:
print (line)
fo.close()
Answer.
Name of the file: myfile.txt
TechBeamers
Hello Viewers!!
25. What will be the output of the following code snippet? (2M)
import sys
print ('Enter your name: ',)
name = ''
while True:
c = sys.stdin.read(1)
if c == '\n':
break
name = name + c
print ('Entered name is:', name)
#Assuming that input given by user is :Our Country
Answer.
Our Country
26. What will be the output of the following code snippet? (2M)
with open("hello.txt", "w") as f:
f.write("Hello World how are you today")
with open('hello.txt', 'r') as f:
data = f.readlines()
for line in data:
words = line.split()
print (words)
f.close()
Answer.
[‘Hello’, ‘World’, ‘how’, ‘are’, ‘you’, ‘today’]
27. What will be the output of the following code snippet? (2M)
f = None
for i in range (5):
with open("myfile.txt", "w") as f:
if i > 2:
break
print (f.closed)
Answer. B TRUE
28. What will be the output of the following code snippet?
f = open("data.txt", "w+")
txt = "This is 1st line\n"
f.writelines( txt )
seq = " This is 2nd line\nThis is 3rd line"
f.seek(0, 2)
f.writelines( seq )
myList = []
for line in f:
myList.append(line)
print(myList)
f.close()
Answer. []
29. What will be the output of the following code snippet?
f = open("data.txt", "r")
txt = "This is 1st line\n"
f.writelines( txt )
f.seek(0,0)
line = f.readlines()
print ("Read Line: %s" % (line))
f.close()
Answer. C IO Error
30. What will be the output of the following code snippet?
try:
f = open("testfile", "r")
f.write("This is the test file for exception handling!!")
except IOError:
print ("Error: could not find a file or read data")
else:
print ("content is written in the file successfully")
Answer. C C. content is written in the file successfully
1. A CSV file is also known as a ….
a) Flat File
b) 3D File
c) String File
d) Random File
2. Which of the following is a string used to terminate lines produced by writer()method of csv module?
a) Line Terminator
b) Enter key
c) Form feed
d) Data Terminator
3. What is the output of the following program?
import csv
d=csv.reader(open('c:\PYPRG\ch13\city.csv'))
next(d)
for row in d:
print(row)
if the file called “city.csv” contain the following details
chennai,mylapore
mumbai,andheri
a) chennai,mylapore
b) mumbai,andheri
c) chennai,mumba
d) chennai,mylapore mumbai,andheri
4. Which of the following creates an object which maps data to a dictionary?
a) listreader()
b) reader()
c) tuplereader()
d) DicReader ()
5. Making some changes in the data of the existing file or adding more data is called
a) Editing
b) Appending
c) Modification
d) Alteration
6. Mention the default modes of the File.
a) Read
b) Write
c) Append
d) Join
7. Every file has its own identity associated with it. Which is known as –
a) icon
b) extension
c) format
d) file type
8. Which of the following is not a known file type?
a) .pdf
b) .jpg
c) .mp3
d) .txp
9. In f=open(“data.txt”, “r”), r refers to __________.
a) File handle
b) File object
c) File Mode
d) Buffer
10. EOL stands for
a) End Of Line
b) End Of List
c) End of Lines
d) End Of Location
11. Which of the following file types allows to store large data files in the computer memory?
a) Text Files
b) Binary Files
c) CSV Files
d) None of these
12. Which of the following file types can be opened with notepad as well as ms excel?
a) Text Files
b) Binary Files
c) CSV Files
d) None of these
13. Which of the following is nor a proper file access mode?
a) Close
b) Read
c) Write
d) append
14. To read 4th line from text file, which of the following statement is true?
a) dt = f.readlines();print(dt[3])
b) dt=f.read(4) ;print(dt[3])
c) dt=f.readline(4);print(dt[3])
d) All of these
15. Which of the following function flushes the files implicitly?
a) flush()
b) close()
c) open()
d) fflush()
16. Which of the following functions flushes the data before closing the file?
a) flush()
b) close()
c) open()
d) fflush()
17. Mention the two ways to read a CSV file using Python. (2M)
18. What is use of next() function? (2M)
19. Write a Python program to read a CSV file with default delimiter comma (,) (2M)
20. What is the difference between the write mode and append mode(2M)
21. Consider following lines for the file “friends.txt” and predict the output: (2M)
Friends are crazy, Friends are naughty !
Friends are honest, Friends are best !
Friends are like keygen, friends are like license key !
We are nothing without friends, Life is not possible without friends !
f = open("friends.txt")
l = f.readline()
l2 = f.readline(18)
ch3=f.read(10)
print(l2)
print(ch3)
print(f.readline())
f.close()
