Review of Phython

Question

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

Answer

Option (i) and (iii) are possible
PICK maxval=3 minval=0

Sponsor Area

Some More Questions From Review of Phython Chapter

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

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

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

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

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

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

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

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

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

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