Carefully study the following Python program that uses functions from the…
PYQ EMRS TGT/PGT (ESSE) 2025
Carefully study the following Python program that uses functions from the random module to generate values and display selected elements from a Python list. Read the code and answer the questions that follow:
_______________ # Line 1
C = list('VIBGYOR')
Extra = 1 + int(2 * random())
Low = randrange(2, 6, 2)
High = randint(Low, 6)
for i in range(Low, High + Extra):
print(C[i], end='#')Questions:
(A) Suggest an appropriate import statement for Line 1 in the above code so that all functions of the random module can be used directly in the program without using the module name prefix.
(B) Identify all possible values that the variable Low can take during program execution.
(C) Based on the logic of the code, determine which one of the given options cannot be a valid output of the program. Briefly justify your answer.
Options:
1. B#G#Y# 2. B#G#Y#O# 3. I#B#G#Y# 4. Y#O#
(D) Identify the situation in which the program may generate a runtime exception. Specify the combination of values of Low, High and Extra that may cause the exception, and name the type of exception raised.
Attempted by 41 students.
Sign up free to check your answer
Sign up freeLoading lesson…

