Page 64 - PYTHON-11
P. 64
Section D (4 × 4 = 16 Marks)
32. (a) Find the possible outputs of the following Python program and determine the possible range for ‘num’.
(4)
import random
msg = "MESSAGE ENCRYPTED"
num = random.randrange(1, 8, 2)
p = 5
while msg[p] != "T":
print(msg[p] + msg[num] + "$", end=" ")
num += 2
p -= 1
OR
(b) Predict the output of the following code.
mssg = "!1234Artificial_Intelligence2025!"
result = ""
for i in range(len(mssg)):
if mssg[i].isalpha():
result += mssg[i - 1]
elif mssg[i].isdigit():
result += "$"
else:
result += "&"
print(result)
Ans. (a) GE$ AS$ SG$ S $ EN$ MR$ DP$ EE$
OR
(b) &$$$$4Artificia&_Intelligenc$$$$&
33. Differentiate between compiler and interpreter. (4)
Ans.
Compiler Interpreter
A compiler debugs the whole program in one go. An interpreter debugs a program line by line.
Errors traced by a compiler are displayed at the An interpreter displays the errors line-wise. It does
end of the program along with their respective line not move on to the next line or execute further
numbers. until the error in the current line is removed.
A compiler program occupies more memory space An interpreter results in more memory wastage
as it generates an executable file (byte code). The since the program is interpreted line by line every
entire object code generated by the compiler resides time the program is executed.
in memory and need not be compiled every time.
A compiler takes less execution time. An interpreter takes more execution time.
34. (a) Explain the commonly used symbols of a flowchart. (4)
OR
(b) Explain two ways of violating Intellectual Property Rights.
Ans. (a) The commonly used symbols of a flowchart are as follows:
Symbol Name What it does in the code
Start/End Ovals show a start point or end point in the code.
Flow Arrows, called Connectors show connection between different
parts of the code.
Process Rectangles show processes, e.g., calculations.
Input/Output Parallelograms show inputs and outputs.
Condition/ Diamonds show a decision/condition (this normally depicts if, if-
Decision else, if-elif-else, while and for).
Connector Represents the ongoing flow across multiple charts or pages.
M.13