12th Standard Syllabus & Materials
12th Standard
TN 12th English Poem - 6 - Incident of the French Camp Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 6 - On the Rule of the Road Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 5 - The Chair Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Supplementary - 4 - The Midnight Visitor Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Poem - 4 - Ulysses Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 4 - The Summit Sample Question Papers Study Material - QB365 Set A

Published on: 03/02/2021
12th Standard Computer Science English Medium Python and CSV Files Reduced Syllabus Important Questions 2021
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
Which option allows to write the double quote or all the values in CSV file?
csv.Quote ( )
csv.ALL_QUOTE( )
csv.QUOTE_ALL ( )
csv.QUOTEALL ( )
2.
How many ways are there to write a new or modify the existing CSV file?
8
6
4
2
3.
Which of the following works with list / tupledict?
read ( )
dictreader ( )
reader ( )
diet ( )
4.
List literals are enclosed with
{ }
( )
< >
[ ]
5.
The function used to add elements to CSV file is
add ( )
write ( )
append ( )
addition ( )
6.
The CSV file contents can be read with the help of the method
read ( )
open ( )
with open ( )
reader ( )
7.
Which python file mode open a file for exclusive creation?
'x'
'w'
't'
'a'
8.
Python function open () returns a file object called
read
write
handle
process
9.
Which of the following built-in function Python has to open a file?
read ()
open ()
reader ()
openfile ()
10.
In CSV file, each record is to be located on a separate line, delimited by a line break by pressing
Enter key
ESV key
Tab key
Shift key
11.
Which of the following is a human readable text file where each line has fields?
CSV file
CSV module
CSV sheet
CSV text
12.
What will be written inside the file test.csv using the following program
import csv
D = [['Exam'],['Quarterly'],['Halfyearly']]
csv.register_dialect('M',lineterminator = '\n')
with open('c:\pyprg\ch13\line2.csv', 'w') as f:
wr = csv.writer(f,dialect='M')
wr.writerows(D)
f.close()
Exam Quarterly Halfyearly
Exam Quarterly Halfyearly
E, Q, H
Exam, Quarterly, Halfyearly
13.
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
chennai,mylapore
mumbai,andheri
chennai,mumba
chennai,mylapore,mumbai,andheri
14.
The command used to skip a row in a CSV file is
next()
skip()
omit()
bounce()
15.
A CSV file is also known as a ….
Flat File
3D File
String File
Random File
16.
What is called modification?
17.
How will you read CSV file into a dictionary?
18.
What is use of sort ( ) method?
19.
Differentiate text mode and binary mode.
20.
What take the three models in which CSV file can be opened?
21.
How the CSV file operation takes place in python?
22.
Why CSV file is known as flat file?
23.
How will you sort more than one column from a csv file?Give an example statement.
24.
Mention the default modes of the File.
25.
What is CSV File?
26.
Write a program to create a new normal CSV file to store data.
27.
What are the different ways of reading a CSV file using reader ( ) method?
28.
Write a program to read a file with default delimiter comma.
29.
Write the syntax of reader( ).
30.
How will you save the CSV file in MS-Excel?
31.
How will you create CSV normal file?
32.
What is the difference between reader() and DictReader() function?
33.
What is the difference between the write mode and append mode.
34.
Write a Python program to read a CSV file with default delimiter comma (,).
35.
Write a note on open() function of python. What is the difference between the two methods?
36.
How will you write the CSV file with custom denote characters? Explain with an example.
37.
Write a program to read the CSV file and store it in a list.
38.
Write a program to read the CSV file through python using reader ( ) method.
39.
Write the rules to be followed to format the data in a CSV file.
40.
Write a Python program to write a CSV File with custom quotes.
41.
Tabulate the different mode with its meaning.
42.
Differentiate Excel file and CSV file.
1.
(c)
csv.QUOTE_ALL ( )
2.
(a)
8
3.
(c)
reader ( )
4.
(d)
[ ]
5.
(c)
append ( )
6.
(d)
reader ( )
7.
(d)
'a'
8.
(c)
handle
9.
(b)
open ()
10.
(a)
Enter key
11.
(a)
CSV file
12.
(d)
Exam, Quarterly, Halfyearly
13.
(b)
mumbai,andheri
14.
(a)
next()
15.
(a)
Flat File
16.
Making some changes in the data of the existing file or adding more data is called modification.
17.
(i) To read a CSV file into a dictionary can be done by using DictReader class of csv module which works similar to the reader ( )class but creates an object which maps data to a dictionary.
(ii) The keys are given by the fieldnames as parameter.
18.
sort ( ) command arranges a list value in ascending order.Iist_name.sort(reverse) is used to arrange a list in descending order.
19.
| Text mode | Binary mode | |
| i) | The default is reading in text mode. | Binary mode returns bytes. |
| ii) | In this mode, while reading from the file the data would be in the format of strings. | This is the mode to be used when dealing with non-text files like image or exe files |
20.
Read 'r', write 'w' or append 'a'.
21.
Python, a file operation takes place in the following order
Step 1: Open a file
Step 2 : Perform Read or write operation
Step 3 : Close the file
22.
A CSV is known as flat file because files in the CSV format can be imported to and exported from programs that store data in tables, such as Microsoft Excel or OpenOfficeCalc
23.
To sort by more than one column you can use itemgetter with multiple indices:
operator.itemgetter
Example:
sortedlist = sorted (data, key = operator. itemgetter(1))
24.
The default is reading in text mode. In this mode, while reading from the file the data would be in the format of strings.
25.
A CSV file is a human readable text file where each line has a number of fields, separated by commas or some other delimiter.
26.
Import csv
csvData = [['Student, 'Age'], [Dhanush', '17'], ['Kalyani', '18'], ['Ram', '15']]
with open('c:\\pyprg\\ch13\\Pupil.csv', 'w') as CF:
writer = csv.writer(CF) # CF is the file object
writer.writerows(csvData) # csvData is the List name
CF.close( )
27.
(i) CSV file - data with default delimiter comma (,)
(ii) CSV file - data with Space at the beginning
(ill) CSV file - data with quotes
(iv) CSV file - data with quotes
28.
#importing csv
import csv
#opening the csv file which is in different location with read mode
with open('c:\\pyprg\\ sample1.csv', 'r') as F:
#other way to open the file is f= ('c:\\pyprg\\ sample1.csv', 'r')
reader = csv.reader(F)
# printing each line of the Data row by row
print(row)
F.close ( )
29.
'The syntax for csv.reader() is
csv.reader(fileobject,delimiter,fmtparams)
where
(i) file object: passes the path and the mode of the file.
(ii) delimiter: an optional parameter containing the standard dilects like , | etc can be omitted
(iii) fmtparams: optional parameter which help to override the default values of the dialects like skipinitialspace, quoting etc. Can be omitted.
30.
To create a CSV file using Microsoft Excel, launch Excel and then open the file you want to save in CSV format. For example. below is the data contained in our sample Excel worksheet:
Once the data is entered in the worksheet, select File ⟶ Save As option, and for the "Save as type option" select CSV (Comma delimited) or type the file name along with extension .csv.
31.
To create a CSV file in Notepad,
(i) First open a new file using
File ⟶New or ctrl +N.
(ii) Then enter the data separating each value with a comma and each row with a new line.
(iii) For example consider the following details
Topic1, Topic2, Topic3
one, two, three
Example1, Example2, Example3
(iv) Save this content in a file with the extension.csv.
32.
The main difference between the csv.reader( ) and DictReader( ) is in simple terms csv.reader and csv.writer work with list/ tuple, while csv. DictReader and csv.DictWriter work with dictionary. csv. DictReader and csv. DictWriter take additional argument fieldnames that are used as dictionary keys.
33.
Write mode:
Open a file for writing. Creates a new file if it does not exist or truncates the file if it exists.
Append mode:
Open for appending at the end of the file without truncating it. Creates a new file if it does not exist.
34.
Program: To read a csv file with comma (,)
#importing csv
import csv
#opening the csv file which is in different location with read mode
with open('c:\\Pyprg\ \sample1.csv', 'r') as F:
#other way to open the file is
f=('C:\\pyprg\\sample1.csv', 'r')
reader = csv.reader(F))
#printing each line of the Data row by row.
print (row)
F. close( )
Output:
['SNO','NAME', 'CITY']
['12101', 'RAM', 'CHENNAI']
['12102', 'LAVANYA' "TIRUCHY']
['12103', 'LAKSHMAN', 'MADURAI']
35.
(i) Python has a built-in function open() to open a file. This function returns a file object also called a handle, as it is used to read or modify the file accordingly.
For Example:
>>>f = open ("sample.txt") #open file in current directory # f is file object
>>> f = open ('c:\\Pyprg\ch13 sample5.csv') # specifying full path
(ii) The default is reading in text mode. In this mode, while reading from the file the data would be in the format of strings.
(iii) On the other hand, binary mode returns bytes and this is the mode to be used when dealing with non-text files like image or exe files.
36.
To write the CSV file with custom quote characters, by registering new dialects using csv. register_dialect( ) class of csv module.
Example:
import csv
csvData = [['SNO",Items'], ['1",Pen'], ['2",Book'], ['3"Pencil']]
csv.register_dialect('myDialect',delimiter = '|',
quotechar = '"', quoting=csv.QUOTE_ALL)
with open('c:\\pyprg\\ch13\\quote.csv', 'w') as csvFile:
writer = csv.writer(csvFile, dialect='myDialect')
writer. writerows( csvData)
print("writing completed")
csvFile.close( )
37.
import csv
# other way of declaring the filename
inFile= 'c:\\pyprg\\sample.csv'
F=open (inFile,' r')
reader = csv.reader(F)
# declaring array
arrayValue = [ ]
# displaying the content of the list for row in reader:
arrayValue.append(row)
print(row)
F.close( )
38.
import csv
csv.register_dialect('myDialect', delimiter = ',',skipinitialspace = True)
F=open('c:\\pyprg\\sample2.csv', 'r')
reader = csv.reader(F, dialect = 'myDialect')
for row in reader:
print(row)
F.close( )
39.
Rules to be followed to format data in a CSV file:
(i) Each record (row of data) is to be located on a separate line, delimited by a line break by pressing enter key.
For example:↲
xxx,yyy↲
↲denotes enter Key to be pressed
(ii) The last record in the file mayor may not have an ending line break.
For example:
ppp, qqq↲
yyy, xxx
(iii) There may be an optional header line appearing as the first line of the file with the same format as normal record lines. The header will contain names corresponding to the fields in the file and should contain the same number of fields as the records in the rest of the file.
For example:
field_name 1, field_name 2, field_name 3↲
aaa,bbb,ccc↲
zzz, yyy, xxx CRLF(Carriage Return and Line Feed)
(iv) Within the header and each record, there may be one or more fields, separated by commas. Spaces are considered part of a field and should not be ignored. The last field in the record must not be followed by a comma.
For example:
Red, Blue
(v) Each field mayor may not be enclosed in double quotes. If fields are not enclosed with double quotes, then double quotes may not appear inside the fields
For example:
"Red","Blue","Green"↲
Black, White, Yellow
(vi) Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.
For example:
Red, ",", Blue CRLF
Red, Blue, Green
(vii) If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be preceded with another double quote.
For example:
"Red, " "Blue", "Green",
White
40.
We can write the csv file with quotes, by registering new dialects using csv.register_dialect() class of csv module.
Program:
import csv
info = [['SNO: 'Person: 'DOB'],
['1', 'Madhu,' '18/12/2001'],
['2', 'Sowmya', '19/2/1998'],
['3', 'Sangeetha', '20/3/1999'],
['4', 'Eshwar', '21/4/2000'],
['5', 'Anand', '22/5/2001']]
csv.register_dialect('MyDialect',quoting=csv.QUOTE_ALL)
with open('c:\\pyprg\\ch13\\person.csv', 'w') as f:
writer = csv.writer(f, dialect='myDialect')
for row in info:
writer. writerow(row)
f.close()
Output
file: "Person.csv"
"SNO","Person", "DOB", "1", "Madhu", "18/12/2001"
"2, "Sowmya", "19/2/1998", "3", "Sangeetha",
"20/3/1999", "4", "Eshwar", "21/4/2000"
"5", "Anand", "22/5/2001".
41.
| Python file modes | Description |
|---|---|
| 'r' | open a file for reading (default) |
| 'w' | Open a file for writing. Creates a new file if it does not exist or truncates the file if it exists. |
| 'x' | Open a file for exclusive creation. If the file already exists, the operation fails. |
| 'a' | Open for appending at the end of the file without truncating it. Creates a new file if it does not exist. |
| 't' | Open in text mode. default |
| 'b' | Open in binary mode. |
| '+' | Open a file for updating (reading and Writing) |
42.
| Excel | CSV |
|---|---|
| Excel is a binary file that holds information about all the worksheets in a file, including both content and formatting | CSV format is a plain text format with a series of values separated by commas. |
| XLS files can only be read by applications that have been especially written to read their format, and can only be written in the same way. | CSV can be opened with any text editor in Windows like notepad, MS Excel, Open Office, etc. |
| Excel is a spreadsheet that saves files into its own proprietary format viz. xls or xlsx | CSV is a format for saving tabular information into a delimited text file with extension .csv |
| Excel consumes-more memory while importing data | Importing CSV files can be much faster, and it also consumes less memory |
12th Standard Syllabus & Materials
12th Standard
TN 12th English Supplementary - 3 - The Hour of Truth (Play) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Poem - 3 - All the World’s a Stage Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 3 - In Celebration of Being Alive Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Supplementary - 2 - Life of Pi Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards