A csv file "States.csv" contains some data about all the states of India. Each record of the file contains the following data: Name of the State, Capital of the State, Population of the State, Official Language of the State.
For example, a sample record in the file is:
['Andhra Pradesh','Amaravati',52221000,'Telugu']Write a Python program which reads the data from this file and appends all those records where population is more than 10000000 into another csv file 'More.csv'.
Note: "States.csv" also contains the Header row. The Header row should NOT be copied to "More.csv".
import csv
with open('States.csv', 'r') as fin, open('More.csv', 'a', newline='') as fout:
reader = csv.reader(fin)
writer = csv.writer(fout)
data = list(reader)
for row in data[1:]:
if int(row[2]) > 10000000:
writer.writerow(row) | List-I | List-II |
| (A) f.seek(-10,1) | (I) From beginning of file, move 10 bytes forward |
| (B) f.seek(10,1) | (II) From current position, move 10 bytes backward |
| (C) f.seek(10) | (III) From current position, move 10 bytes forward |
| (D) f.seek(-10,2) | (IV) From end of the file, move 10 bytes backward |
Arrange the following in correct order of exception handling in python:
(A) Write the code that may raise an exception inside a try block
(B) Execute some code regardless of whether the exception occurs or not using the finally block
(C) Handle the specific exception using the except block
(D) Raise the exception using the raise statement if necessary
Choose the correct answer from the options given below: