Python Random Module Board Questions


  1. What possible output from the given options is expected to be displayed when the following Python code is executed ? [1 MARK] [2024]

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

  3. What possible output(s) are expected to be displayed on screen at the time of execution of the following program : [2 MARKS] [2023]

    import random
    M= [5, 10, 15, 20, 25, 30]
    for i in range(1, 3):
          first= random.randint(2, 5) - 1
          sec= random.randint(3, 6) - 2
          third= random.randint(1, 4)
          print(M[first], M[sec], M[third], sep="#")
    
    (a) 10#25#15
        20#25#25		
    
    (b) 5#25#20
        25#20#15		
    
    (c)  30#20#20
         20#25#25	
    
    (d) 10#15#25#
        15#20#10#
    
  4. (a) 10#25#15
        20#25#25