1st Half(Bcs) Ans
1st Half(Bcs) Ans
1st Half(Bcs) Ans
General Instructions:
This question paper contains 37 questions.
● All questions are compulsory.
● The paper is divided into 5 Sections- A, B, C, D and E.
● Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
● Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
● Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
● Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
● Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
● All programming questions are to be answered using Python Language only.
● In case of MCQ, text of the correct answer should also be written.
27. Complete the following snippet to open the file and create a writer object for a csv file “emp.csv” with
delimiter as pipe symbol „|‟ to add 5 more records into the file using the list named “e_rec”.
emp_file=___________
csv_writer=csv.writer( ____________ )
Ans:
emp_file=open(“emp.csv”,”ab”)
csv_writer=csv.writer( e_rec,emp_file )
28. Consider the given string and write the output for the following:
Str1=”Augmented reality”
a) Str1[0:3] b) Str1[::3]
Ans: a) Aug b) “Amt at”
Answer:
Text files are plain text files which are used to store any kind of text which has no fixed
format. whereas, CSV files are also text files but they can store information in a specific
format only.
def Insert():
L=[]
while True:
ClockID = input("Enter Clock ID = ")
ClockName = input("Enter Clock Name = ")
YearofManf = int(input("Enter Year of Manufacture = "))
price = float(input("Enter Price = "))
R = [ClockID, ClockName, YearofManf, price]
L.append(R)
ans = input("Do you want to enter more records (Y/N)=")
if ans.upper()=='N':
break
import csv
fout = open('watch.csv','a',newline='')
W = csv.writer(fout)
W.writerows(L)
fout.close()
print("Records successfully saved")
def Delete():
ClockID = input("Enter Clock ID to be removed = ")
found = False
import csv
fin = open('watch.csv','r')
R = csv.reader(fin)
34. Write a function V_COUNT() to read each line from the text file and count number of lines begins and ends with
any vowel.
Example:
Eshwar returned from office and had a cup of tea.
Veena and Vinu were good friends.
Anusha lost her cycle.
Arise! Awake! Shine.
The function must give the output as:
Number of Lines begins and ends with a vowel is 3
Ans:
def V_COUNT():
f=open("string_begin.txt","r")
L=" "
c=0
for i in f:
print(len(i))
if i[0] in"aeiouAEIOU" and i[-2] in "aeiouAEIOU":
c=c+1
print("Number of Lines begins and ends with a vowel is",c)
V_COUNT()