Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views6 pages

CW Random Numbers

Random numbers python
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)
10 views6 pages

CW Random Numbers

Random numbers python
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/ 6

Que.

1
#fill in the blanks for the statement1 with the help of random function

#if the number generated by the random number is supposed to be between

the range of 20-2000.

#r= //statement 1

print(r)

Que. 2

#fill in the blanks for the statement1 with the help of random function

#if the number generated by the random number is supposed to be between

the range of 41-441.

#r= //statement 1

print(r)

Que. 3

low=25

point =5

for i in range (1,5):

Number=low + random.randrange(0,point)

print(Number,end=":")

point-=1;

#Output Options:

i. 29: 26:25 :28 : ii. 24: 28:25 :26 :


iii. 29: 26:24 :28 : iv. 29: 26:25 :26:

Que. 4

p=99

q=999

x=random.randrange(0,3)+4

y=random.randrange(0,2)+2

for i in range(x):

print("#",end="")

print(p,"-",end="") for i in range(x):

print("@",end="") print(q)

#Output Options:

i. ##99-@999

ii. ##99-@@999

iii. ######99-@@999

iv. ####99-@@@

Que. 5

MIN = 25

SCORE = 10

for i in range (1,5):

Num = MIN + random.randrange(0,SCORE)

print(Num,end=":")

SCORE-=1;
#Output Options:

i. 34:31:30:33:

ii. 29:33:30:31:

iii. 34:31:30:31:

iv. 34:31:29:33:

Que. 6

A="WELCOME"

ToGo=2

for I in range (len(A)):

ToGo=random.randrange(0,2*2) +1;

print(A[ToGo],end=":")

#Output Options:

i. W: E: L: C: O:M: E:

ii. E: C: E: E: C: C: E:

iii. E: C: E: E: C:C: O:

iv. C: C: C: E: E: C: C:

PRACTICE # 2
Q.no.1
import random serial=['E', 'X', 'A', 'M’]
number=[ 69, 66, 67, 68] print(number[random.randrange(0,3)],end=‘’)
for i in range (4):
print(serial[2+ random.randrange(0,2) - 1],end=‘’)

#Output Options:

66AAXA
67AAAM
67XXAX
69AXXA

Answer:

, iii) &iv)
q.no.2

import random Max=4;


Mynum=20+random.randrange(0,Max)
for N in range (Mynum,26): print(N,end="*")

#Output Options:
i. 20*21*22*23*24*25* ii.22*23*24*25*
iii. 23*24*
iv. 21*22*23*24*25

Answer:

i& ii
q.no.3

import random
Area=["NORTH","SOUTH","EAST","WEST"]
for I in range(3): ToGo=random.randint(0,2) + 1 print(Area[ToGo],end=":")

#Output Options:
SOUTH : EAST : SOUTH:
NORTH : SOUTH : EAST:
SOUTH : EAST : WEST:
SOUTH : EAST :EAST

Answer:

&iii

q.no.4
import random
Disp=22 Rnd=random.randrange(0,Disp)+15 N=1
for I in range(3,Rnd,4):
print(N,end=" ") N+=1

#Output Options:

1
1 2 34
12
1 23

Answer:

&iv
q.no.5

import random
MAX = 3
digit =80 + random.randrange(0,MAX ) for R in range (digit,80-1,-1):
print(R,end="$")

#Output Options:

i. 83$82$81$80$ ii. 80$81$82$


iii. 80$81$ iv. 81$80$

Answer:

iv
q.no.6
import random l=[10,7,21]
x=random.randint(1,2) for i in range(x):
y=random.randint(1,x)
print(l[y],”$”,end=“ “)

#Output Options:

i) 10$ 7$

ii) 21$ 7$

iii) 21$ 10$

v) 7$

Answer:

&iv)

You might also like