2/10/26, 5:06 PM Chapter Wise
Random module
The random module lets you generate random numbers and selections, which is
especially useful in games, testing, simulations, and dynamic content generation.
Before using its functions, make sure to:
import random
🔹 1. [Link]()
Description: Returns a random float number between 0.0 and 1.0
Syntax: [Link]()
Use Case: For probability, simulation, or generating random float values
import random
print([Link]()) # Output: 0.3748... (between 0.0 and 1.0)
🔹 2. [Link](a, b)
Description: Returns a random integer between a and b (inclusive)
Syntax: [Link](start, end)
Use Case: Ideal when you need a whole number within a range
print([Link](1, 10)) # Could be any number from 1 to 10, includin
🔹 3. [Link](start, stop, step)
Description: Returns a randomly selected element from range(start, stop, step)
Syntax: [Link](start, stop, [step])
Use Case: When you want a random number from a range, excluding the stop value
print([Link](10)) # Random int from 0 to 9
print([Link](1, 10)) # Random int from 1 to 9
[Link]:8000/articles/?grade=9&subject=21 1/7
2/10/26, 5:06 PM Chapter Wise
print([Link](0, 100, 5)) # Random multiple of 5 between 0 and 95
🔹 Q1
print([Link](1, 5))
📝 Output:
🔹 Q2
print(round([Link](), 2))
📝 Output:
🔹 Q3
print([Link](10, 21, 5))
📝 Output:
🔹 Q4
colors = ['Red', 'Blue', 'Green']
print([Link](colors))
📝 Output:
[Link]:8000/articles/?grade=9&subject=21 2/7
2/10/26, 5:06 PM Chapter Wise
🔹 Q5
for i in range(3):
print([Link](100, 105))
📝 Output:
🔹 Q6
print([Link]() * 10)
📝 Output:
🔹 Q7
print([Link](1, 10))
📝 Output:
🔹 Q8
otp = [Link](1000, 9999)
print("OTP:", otp)
📝 Output:
🔹 Q9
[Link]:8000/articles/?grade=9&subject=21 3/7
2/10/26, 5:06 PM Chapter Wise
import random
lst = [40,60,70,90,20]
first = [Link](0,3)
last = [Link](2,3)
for i in range(first,last+1):
print(lst[i],"#",end="")
(i) 90#
(ii) 60 #70 #
(iii) 40 #60 #70 #
(iv) 40 #60 #20 #
🔁 Q10
import random
lst = [10, 20, 30, 40, 50]
start = [Link](0, 2)
stop = [Link](2, 4)
for i in range(start, stop + 1):
print(lst[i], end="*")
(i) 30*40*
(ii) 10*20*30*
(iii) 20*
(iv) 50*60*
🔁 Q11
import random
items = ['a', 'e', 'i', 'o', 'u']
[Link]:8000/articles/?grade=9&subject=21 4/7
2/10/26, 5:06 PM Chapter Wise
pos = [Link](1, 3)
for i in range(pos):
print(items[i], end="-")
(i) a-e-i-
(ii) a-e-
(iii) a-
(iv) e-i-o-
🔁 Q12
import random
data = ["CBSE", "ISC", "NIOS", "IB"]
i = [Link](0, len(data) - 2)
print(data[i], data[i+1])
(i) CBSE ISC
(ii) ISC NIOS
(iii) NIOS IB
(iv) IB CBSE
🔁 Q13
import random
nums = [5, 10, 15, 20, 25]
x = [Link](nums)
print("Chosen:", x, ", Square:", x**2)
(i) Chosen: 10 , Square: 100
(ii) Chosen: 15 , Square: 225
[Link]:8000/articles/?grade=9&subject=21 5/7
2/10/26, 5:06 PM Chapter Wise
(iii) Chosen: 25 , Square: 625
(iv) Chosen: 50 , Square: 2500
🔁 Q14
import random
letters = list("CODE")
for i in range([Link](1, 3)):
print([Link](letters), end="#")
(i) C#O#D#
(ii) E#
(iii) O#E#
(iv) CODE#
CBSE PREVIOUS YEAR QUESTIONS
1. What possible output(s) are expected to be displayed on screen at the time of execution
of the program from the following code? Also specify the minimum and maximum values
that can be assigned to the variable End.
import random
Colours = ["VIOLET","INDIGO","BLUE","GREEN", "YELLOW","ORANGE","RED"]
End = randrange(2)+3
Begin = randrange(End)+1
for i in range(Begin,End):
print(Colours[i],end="&")
(i) INDIGO&BLUE&GREEN&
(ii) VIOLET&INDIGO&BLUE&
(iii) BLUE&GREEN&YELLOW&
(iv) GREEN&YELLOW&ORANGE&
[Link]:8000/articles/?grade=9&subject=21 6/7
2/10/26, 5:06 PM Chapter Wise
2. What possible output(s) are expected to be displayed on screen at the time of execution
of the program from the following code?
import random
Cards = ["Heart", "Spade", "Club", "Diamond"]
for i in range(2):
print(Cards[[Link](1, i + 2)], end="#")
(A) Spade#Diamond#
(B) Spade#Heart#
(C) Diamond#Club#
(D) Heart#Spade#
3. What possible output(s) are expected to be displayed on screen at the time of execution
of the program from the following code?
import random
Signal = ['RED', 'YELLOW', 'GREEN']
for K in range(2, 0, -1):
R = [Link](K)
print(Signal[R], end='#')
(a) YELLOW#RED#
(b) RED#GREEN#
(c) GREEN#RED#
(d) YELLOW#GREEN#
[Link]:8000/articles/?grade=9&subject=21 7/7