Revision Assignment CS
Revision Assignment CS
(a)Both (A) and (R) are true and (R)is the correct explanation for (A).
(b) Both (A) and (R) are true and (R)is not the correct explanation for (A).
(c) (A)
is true but (R) is
false.
L. ASsertion (A) :CSV file is a human readable text file where each line has a number of fields, separated
by comma or some other delimiter. Reason
Reason (R): sort() does not exist as a method/function for strings in Python.
3.Sangeetais a Python programmerworking in a computer hardware company. She has to maintain the
records of the peripheral devices. She created a csv file named Peripheral.csv, to store the details.
count and number peripheral devices whose price is less than 1000.
Count Device():To display of
a binary file, items.dat, containing records stored in the given format: fitem id:
4, Consider
name,amount]}Write a function,Copy_new),that copies all records whose amount is greater
fitem
be evaluated to in Python
?
5. What will the following expression
A=(6/3 + 4**3//8- 4)
Print(A)
false.
(c) (A) is true but (R) is
(R) is true.
(d) (A) is false but
O. ASsertion (A): readlines() reads all the lines from a text file and returns the lines along with newline as
a list of
strings.
Keasoning (R) :readline() can read the entire text file line by line without using any looping statements.
8.
Write a function in Python that displays the book names having "Y'or 'y'in their name
|froma text file "Bookname.txt".
Exampie :
|If the file "Bookname.txt" contains the names of following books :
12.
normally.
|with "0' in reverse order. The rest of the content
is displayed
Example :
|Output will be :
UBUNTU IS AN NEPO SoURCE GNITAREPO SYSTEM
13.
Write a
function
search replace () Python which accepts a list L ofnumbers and a
number to be searched. in
not exist, an
If the
number exists, it is replaced by 0 and if the number does
appropriatemessage is displayed.
Example:
L= [10,20,30,10,40)
Number to be
searched = 10
|List after
replacement :
L = O.20.30.0.401
i4.
Write a point of difference between append (a) and write (w) modes in a text file.
write a program in Python that defines and calis the fotiowing user defined
la Add Teacher() :It accepts the values from the user and inserts record
functions
of a
:
teacher
toa csv file Teacher.csv'. Each record consists of a list with field elements as
T id,Tname and desig to store teacher D, teacher name and designation
respectively.
Jti) :
Search_Teacher() To display the records of alt the PGT (designation) teachere
16.
jWrite a program in Python that defines and calls the following user defined functions :
li) Add_ Device() :The function accepts and adds records of the peripheral devices toa
csy file 'peripheral.csv'. Each record consists of a list with field elementsas p id
P name and Price to store peripheral device lD, device name, and price
respectively.
Já) Count_Device() : To count and display number of peripheral devices, whose price is
19.
(a) Both (À)and (R)are true and (R) is the correctexplanation for (À).
(b) Both (A) and (R) are true and (R) is not the correct explanation for
(A).
21.
Atharva is a Python tofind and return
the maximum value programmer working on a program
from the list. The code written below has syntactical
errors. Rewrite the correct code and underline the corrections made.
def max num (L) :
max-L (0)
for a in L :
if a> max
max=a
return maX
22.
Harion uigmernt
(b) Beth (A) and (R) ase thue lut (R)anet sthe
3 name PesibhesalL.csy
btructue IPidPhdme, Price
(aldddevice CO
import CSV
def Add_
f=iopenG
p
Device ():
csV. Ariter
Peripheral.
f)
csu', 'a'neviliae = )
while True:
Add
f.close()Joh
Device )
aoa
Page No
(bCount levice O:
import
def
csV
Count
fraopen
Device (): no hA
("Peripheral.csu''ni)
A
csv. reader )
C)
hext (r)
for i in ri
Litilal< 1o004
print (i)
c+=1
f.close()
CountiDeice ()ada")
4.
athuctse = itenid iteiname,amount J
w importpickle na
def Copy ne iaO:ha 4'r
fl= open items dat""rb)
23 open
Count=0
"ne-ikems dat "abos
try
nhile True:
cOunt t =1
tiExceptoirA"apdog1DN
fl.cdose )
42. close )
retunh count
Copyhen()
sl3+ 64lg- 4
2.0 + 4l8-4
2.0+ 8-4
10.0- 4
6,0
but R) iu
q.-2.
1o.20 $4
Adef func():
f= open (" Bookname.txt" 'n!) sli
defreadlines ()
for i in d:
if 'y in i on 'y' in ii
print ()
f.close (O
func )
a def RevlString (O1
ke if::-11
print (kendal)
else:
print i =")
end
fclose()
Rev Strin O)
Paga No:
Date:
oi found.e1 hilntoh
iffound
d o) dunprint('Nümben not found)
else :
print (L),nad
L= [10, 20, 30,40, 40]
SN=10
search replace (L,SN)
1943
14SEARNIN Gg C.
Luseite mode(w)
De ereate a
to iseta te eomtet
it abay eristr.
CSV
(0iaport
def Add. Teacher ):
(" Teacher. csv"'a', newline )
pa csV f).
riter (f)
hiriter taho A
tohtte ruei
Date:
AddTeacher (1
hext (d)
for iin dih
it iL2]=="pI":
print (i)
fuclose).
SearchTeachar(O
16
(Repeat-edLquatin)(Sane as Ques 3).
b) Tup.insert (2,3)
ase imutable
Stateenti 2 and 4.
19)
4+3*5/3 -5%2.
4+ 15/3-5%o2
4+ 5.0 -5 %2
4+ 5.0- 1
9.0 -1
8.0
22."Rajat""Rajan"Ashish"]