CBSE · 083Class XII · 2025Section B2 marks
Question 25
4 March 2025 · Computer Science (083)
What possible output from the given options is expected to be displayed when the following code is executed ?
python
import random
Cards=["Heart","Spade","Club","Diamond"]
for i in range(2) :
print(Cards[random.randint(1,i+2)],end="#")Answer
(a) Spade#Diamond#
Explanation
In iter 1 (i=0), range is (1,2) -> index 1 or 2. In iter 2 (i=1), range is (1,3) -> index 1, 2, 3. 'Spade' is index 1. 'Diamond' is index 3. Sequence (1, 3) is valid.