CBSE · 083Class XII · 2024Section A1 mark

Question 04

2 April 2024 · Computer Science (083)

What possible output from the given options is expected to be displayed when the following Python code is executed ?

python
import random
Signal = ['RED', 'YELLOW', 'GREEN']
for K in range(2, 0, -1) :
    R = random.randrange(K)
    print(Signal[R], end = '#')

Answer

(a) YELLOW # RED #

Explanation

The loop runs for K=2 and K=1. For K=2, R is 0 or 1. For K=1, R is 0. 'YELLOW # RED #' is a possible output.