Review of Phython

Sponsor Area

Question
CBSEENCO12011531

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

  • total

  • 7Salute

  • Que$tion

  • global

Solution

A.

total

Sponsor Area

Question
CBSEENCO12011532

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

Solution

(i) Ceil() function requires math module.
(ii) randint() function requires randon module.

Question
CBSEENCO12011533

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

Solution

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

Question
CBSEENCO12011534

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

Solution

The Output of the given Python code is,
['41', '32', '15', '94']