Python KBA AND SBA
Python KBA AND SBA:
Below pdf includes both kba and sba,
kba means to be mcq/quiz
sba means to be programming/code challenge
There are more available on https://play.google.com/store/apps/details?id=com.master.askmastermaterial
Kba sample
Subject: Python
1.select the list comprehension code equivalent to the below script.
sum=[] for x in (range(1,3)
for y in range(3,6)
sum.append(x+y)
1.sum=[x + y for x in range(1,3) for y in range(3,6)]
2.sum=for x in range(1,3) for y in range(3,6) print x+y]
3.sum=[ return x+y for y in range(1,3) for x in range(3,6)]
4.sum=[ for x in range(1,3) for y in range(3,6) return x+y]
2. which function is used to read two charecters from a file object in file?
a. infile.readline(2)
b.infile.read(2)
c.infile.read()
d.infile.readlines(2)
Sba sample
from collections import Counter
class Book:
def __init__(self,bid,bname,sub,bprice):
self.bid=bid
self.bname=bname
self.sub=sub
self.bprice=bprice
class Library:
def __init__(self,lname,blist):
self.lname=lname
self.blist=blist
def subjectwisebooks(self):
l=[]
for i in self.blist:
l.append(i.sub)
c=Counter(l)
li=sorted(c.items(),key=lambda t:t[1])
di=dict(li)
for i,j in di.items():
print(i,j)
def checkBookCategoryByPrice(self,bidd):
for i in self.blist:
if i.bid==bidd:
if i.bprice>=1000:
print("High Price")
elif i.bprice>=750 and i.bprice<1000:
print("Medium Price")
elif i.bprice>=500 and i.bprice<750:
print("Average Price")
else:
print("Low Price")
b=[]
for i in range(int(input())):
bid=int(input())
bname=input()
sub=input()
bprice=int(input())
b.append(Book(bid,bname,sub,bprice))
bidd=int(input())
l=Library("abcd",b)
l.subjectwisebooks()
l.checkBookCategoryByPrice(bidd)
Comments
Post a Comment