CBSE computer and communication technology

Sponsor Area

Question
CBSEENCO12011578

Which of the following can be used as a valid variable identifier(s) in Python?

  • 4thSum

  • Total

  • Number#

  • Data

Solution

B.

Total

D.

Data

Sponsor Area

Question
CBSEENCO12011579

Name the Python Library modules which need to be imported to invoke the following functions
(i) floor()
(ii) randint()

Solution

Python Library modules which need to import to invoke the given functions are:
(i) math
(ii) random

Question
CBSEENCO12011580

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

Solution

STRING= 'WELCOME'
NOTE=''
for S in range (0,8):
print STRING [S]
print S, STRING
Also, range(0,8) will give a runtime error as the index is out of range. It should be range(0,7)

Question
CBSEENCO12011581

Find and write the output of the following python code:

TXT = ['20','50','30','40']
CNT = 3
TOTAL = 0
for C in [7,5,4,6]:
	T = TXT[CNT]
	TOTAL = float (T) + C
	print

Solution

Output: 
47.0
35.0
54.0
26.0

Question
CBSEENCO12011582

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()

Solution

Output:
101: Pad # 125
102: U Clip # 150
105: Thumb Pin # 35