Sponsor Area
Name the Python Library modules which need to be imported to invoke the following functions:
(i) ceil()
(ii) randint()
(i) Ceil() function requires math module.
(ii) randint() function requires randon module.
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
TEXT=''GREAT
DAY''
for T in range[0,7]:
print TEXT(T)
print T+TEXT
TEXT = 'GREAT'
DAY = ''
for T in range (0,7):
print TEXT [T]
print T, TEXT
The range(0,7) will give a runtime error as the index is out of range. It should be a range(0,6).
Find and write the output of the following Python code:
STR = ['90','10','30','40']
COUNT = 3
SUM = 0
for I in [1,2,5,4]:
S = STR[COUNT]
SUM = float (S)+I
print SUM
COUNT-=1
The Output of the given Python code is,
['41', '32', '15', '94']
Find and write the output of the following Python code :
class ITEM:
def __init__(self,I=101,N='Pen',Q=10): #constructor
self.Ino=I
self.IName=N
self.Qty=int(Q);
def Buy(self,Q):
self.Qty = self.Qty + Q
def Sell(self,Q):
self.Qty -= Q
def ShowStock(self):
print self.Ino,':',self.IName,'#',self.Qty
I1=ITEM()
I2=ITEM(100,'Eraser',100)
I3=ITEM(102,'Sharpener')
I1.Buy(10)
I2.Sell(25)
I3.Buy(75)
I3.ShowStock()
I1.ShowStock()
I2.ShowStock()
The Output of the given python code is,
102: Sharpener # 85
101: Pen # 20
100: Eraser # 75
What is the possible outcome(s) executed from the following code? Also, specify the maximum and minimum values that can be assigned to variable N.
import random
SIDES=['EAST','WEST','NORTH','SOUTH'];
N=random.randint(1,3)
OUT=''
for I in range(N,1,-1):
OUT=OUT+SIDES[I]
print OUT
SOUTHNORTH | SOUTHNORTHWEST |
SOUTH | EASTWESTNORTH |
The maximum and minimum values that can be assigned to variable N given as,
Maximum value of N = 3
Minimum value of N = 1
The possible outcome(s) print from the given code is SOUTHNORTH.
Name the Python Library modules which need to be imported to invoke the following functions
(i) floor()
(ii) randint()
Python Library modules which need to import to invoke the given functions are:
(i) math
(ii) random
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
STRING=''WELCOME
NOTE''
for S in range[0,8]:
print STRING(S)
print S+STRING
STRING= 'WELCOME'Also, range(0,8) will give a runtime error as the index is out of range. It should be range(0,7)
NOTE=''
for S in range (0,8):
print STRING [S]
print S, STRING
Find and write the output of the following python code:
class INVENTORY:
def __init__(self,C=101,N='Pad',Q=100): #constructor
self.Code=C
self.IName=N
self.Qty=int(Q);
def Procure(self,Q):
self.Qty = self.Qty + Q
def Issue(self,Q):
self.Qty -= Q
def Status(self):
print self.Code,':',self.IName,'#',self.Qty
I1=INVENTORY()
I2=INVENTORY(105,'Thumb Pin',50)
I3=INVENTORY(102,'U Clip')
I1.Procure(25)
I2.Issue(15)
I3.Procure(50)
I1.Status()
I3.Status()
I2.Status()
Output:
101: Pad # 125
102: U Clip # 150
105: Thumb Pin # 35
What is the possible outcome(s) executed from the following code? Also, specify the maximum and minimum values that can be assigned to variable N.
import random
NAV = ['LEFT','FRONT','RIGHT','BACK'];
NUM = random.randint(1,3)
NAVG = ''
for C in range(NUM,1,-1):
NAVG = NAVG+NAV[I]
print NAVG
(i)BACKRIGHT | (ii)BACKRIGHTFRONT |
(iii) BACK | (iv) LEFTFRONTRIGHT |
BACKRIGHT
For Variable Number
Max Value - 3
Min Value - 1
Write definition of a method EvenSum(NUMBERS) to add those values in the list of NUMBERS, which are odd.
def EvenSum(NUMBERS):
n=len(NUMBERS)
s=0
for i in range(n):
if (i%2!=0):
s=s+NUMBERS[i]
print(s)
Out of the following, find those identifiers, which can not be used for naming Variable or Functions in a Python program:
_Cost, Price*Qty, float, Switch,
Address One, Delete, Number12, do
Price*Qty, float, Address One, doThese above identifiers cannot be used for naming Variable or Functions in a python program.
Name the Python Library modules which need to be imported to invoke the following functions
(i) load()
(ii) pow()
The Python Library modules which need to be imported to invoke the given functions are,
(i) pickle
(ii) math
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
for Name in [Amar, Shveta, Parag]
IF Name[0]='S':
print(Name)
for Name in [ 'Amar','Shveta','Parag']:
if Name[0] == 'S':
print(Name)
Sponsor Area
Find and write the output of the following python code:
class Notes:
def __init__(self,N=100,Nt='CBSE'): #constructor
self.Nno=N
self.NName=Nt
def Allocate(self, N,Nt):
self.Nno= self.Nno + N
self.NName= Nt + self.NName
def Show(self):
print(self.Nno,'#',self.NName)
s=Notes()
t=Notes(200)
u=Notes(300,'Made Easy')
s.Show()
t.Show()
u.Show()
s.Allocate(4, 'Made ')
t.Allocate(10,'Easy ')
u.Allocate(25,'Made Easy')
s.Show()
t.Show()
u.Show()
Output:
100 # CBSE
200 # CBSE
300 # Made Easy
104 # Made CBSE
210 # Easy CBSE
325 # Made EasyMade Easy
What are the possible outcome(s) executed from the following code? Also, specify the maximum and minimum values that can be assigned to variable PICKER.
import random
PICK=random.randint(0,3)
CITY=['DELHI','MUMBAI','CHENNAI','KOLKATA']
for I in CITY:
for J in range(1,PICK):
print(I,end='')
print()
i | ii |
DELHIDELHI MUMBAIMUMBAI CHENNAICHENNAI KOLKATAKOLKATA |
DELHI DELHIMUMBAI DELHIMUMBAICHENNAI |
iii | iv |
DELHI MUMBAI CHENNAI KOLKATA |
DELHI MUMBAIMUMBAI KOLKATAKOLKATAKOLKATA |
Option (i) and (iii) are possible
PICK maxval=3 minval=0
Observe the following STUDENTS and EVENTS tables carefully and write the name of the RDBMS operation which will be used to produce the output as shown in LIST? Also, find the Degree and Cardinality of the LIST.
STUDENTS
No | Name |
1 | Tara Mani |
2 | Jaya Sarkar |
3 | Tarini Trikha |
EVENTS
EVENTCODE | EVENTNAME |
1001 | Programming |
1002 | IT Quiz |
LIST
NO | NAME | EVENTCODE | EVENTNAME |
1 | Tara Mani | 1001 | Programming |
1 | Tara Mani | 1002 | IT Quiz |
2 | Jaya Sarkar | 1001 | Programming |
2 | Jaya Sarkar | 1002 | IT Quiz |
3 | Tarini Trikha | 1001 | Programming |
3 | Tarini Trikhar | 1002 | IT Quiz |
Cartesian Product
Degree = 4
Cardinality = 6
How is __init__() different from __del__() ?
__init__() is the class constructor or initialization method which is automatically invoked when we create a new instance of a class.
__del__() is a destructor which is automatically invoked when an object (instance) goes out of scope.
For Example:
class Sample:
def __init__(self):
self.data = 79
print('Data:',self.data,'created')
def __del__(self):
print('Data:',self.data,'deleted')
s = Sample()
del s
Name the function/method required to
Required Function
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code.
def Tot(Number) #Method to find Total
Sum=0
for C in Range (1, Number+1):
Sum+=C
RETURN Sum
print Tot[3] #Function Calls
print Tot[6]
def Tot(Number): #Method to find Total #Error 1
Sum=0
for C in range (1, Number+1): #Error 2
Sum+=C
return Sum #Error 3
print Tot(3) #Function Call #Error 4
print Tot(6) #Error 4
Find and write the output of the following python code:
class Worker :
def_init_(self,id,name): #constructor
self.ID=id
self.NAME=name
def Change (self):
self.ID=self.ID+10
self.NAME='Harish'
def Display(self,ROW):
print self.ID,self.NAME,ROW
w=Worker(55,'Fardeen')
w.Display(l)
w.Change( )
w.Display(2)
print w.ID+len(w.NAME)
Output:
55 Fardeen 1
65 Harish 2
71
What are the possible outcome(s) executed from the following code? Also specify the maximum and minimum values that can be assigned to variable NUMBER.
STRING=CBSEONLINE
NUMBER=random.randint(0,3)
N=9
while STRING[N]!='L':
print STRING[N]+STRING[NUMBER]+'#',
NUMBER=NUMBER + 1
N=Nl
(i) | (ii) | (iii) | (iv) |
ES#NE#IO# | LE#NO#ON# | NS#IE#LO# | EC#NB#IS# |
(i) ES#NE#IO#
(iv) EC#NB#IS#
Minimum value of NUMBER = 0
Maximum value of NUMBER = 3
Sponsor Area
Sponsor Area