KEMBAR78
Random Solution | PDF | Theoretical Computer Science | Computer Programming
0% found this document useful (0 votes)
149 views2 pages

Random Solution

The document contains 8 questions about using the random module in Python. The questions cover generating random numbers within a range, randomly selecting elements from lists, and using random numbers to control loops and string slicing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views2 pages

Random Solution

The document contains 8 questions about using the random module in Python. The questions cover generating random numbers within a range, randomly selecting elements from lists, and using random numbers to control loops and string slicing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

WORKSHEET - RANDOM MODULE

1.

import random
print(15+random.random()*5)

a) 51.318148965691293
b) 14.318148965691293
c) 15.318148965691293
d) 13.318148965691293

2.

import random
print(65+random.random())

a) 65
b) 6.1811405273901
c) 65.2
d) 65.18114052739017

3.

import random
sub=['CS','IP','FA','LS','EP']
begin=random.randint(1,3)
for i in range(begin):
print(sub[i])

a) CS IP FA
b) CS LS FA
c) EP IP FA
d) CS IP LS

4.

import random
sub=['CS','IP','FA','LS','EP','ENG','PHY']
begin=random.randint(1,2)
last=random.randint(begin,4)
for i in range(begin,last+1):
print(sub[i],end=" ")

a) IP CSLS
b) IP FA CS
c) CSFA LS
d) IP FA LS

5. Import random
mylist = ["apple", "banana", "cherry","mango","grapes"]
picker= 1+random.randint(0,2)
for i in range(1,picker+1): #Outer Loop

for j in range(i+1): #Inner Loop


print(mylist[i],end=" ")
print()
a)banana banana
apple appleapple
mango mangomangomango
b) banana banana
cherry cherrycherry
mango mangomangomango
c)grapes
cherry cherrycherry
mango mangomangomango
d)apple
cherry cherrycherry
mango mangomangomango

6.

import random
alpha=['T','U','V','W']
d=[2,6,7,3]
print("The winner is",end=" ")
print(alpha[random.randrange(0,3)],end=" ")
for i in range(4):
print(d[1-random.randrange(0,2)] ,end=" ")

a) The winner is V 6 2 6 2
b) The winner is W 7 3 6 2
c) The winner is U 2 6 2 2
d) All of the mentioned

7.#Also find the minimum and maximum value, which can be assigned to variable n
import random
n=0
max=5
n=15+random.randint(0,max)
for i in range(n,20):
print(i,'$',end="")
a) 16 $17 $18 $19
b) 16 $17 $18 $19 $
c) 18 $19 $
d) 16 $14 $18 $19 $

8.
import random
text="Digital India"
count=random. randint (0,3)
c=9
while text[c]!='l':
print(text[c]+text[count]+"*”, end=" ")
count=count-1
c=c-1
a) iD* Ia* i*
b) nD* Ia* i*
c) dD* Ia* i*
d) nD* Ia* i

You might also like