0% found this document useful (0 votes)
11 views2 pages

Random Notes

Random notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Random Notes

Random notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

RANDOM

#python libraries
import random
print(random.random()) # 0 to < 1.0 (any value)

print(random.random()*5) # 0 to <5.0 (any value)

#to generate 11 to 15 (in decimal) 11 to < 15.0


print(random.random()*(15-11)+11)

#to generate 11 to 15 (in decimal) 11 to 15.9


print(random.random()*(15-11+1)+11) #(UB-LB+1)+LB

###########USE OF randint()#################
print(random.randint(11,15)) # generate 11 to 15 both will be
inclusive
OUTPUTS
0.7904609768532149
3.1238143991894014
11.525392887525182
14.440064084026417
15
STRING = “CBSEONLINE”
NUMBER=random.randint(0,3) # 0, 1, 2, 3
N=9
While STRING[N] != ’L’
print(STRING[N] + STRING[NUMBER] + ‘#’,end=’’)
NUMBER=NUMBER+1
N=N-1
I) ES#NE#IO# (POSSIBLE OUTPUTS)
II) LE#NO#ON#
III) NS#IE#LO#
IV) EC#NB#IS# (POSSIBLE OUTPUTS)
Minimum value for NUMBER = 0 AND MAXIMUM=3
Dry run
N=9,8,7,6
NUMBER=3, 4, 5, 6
String = C B S E O N L I N E
0 9
EC, EB, ES, EE
NB, NC, NE, NO
IS, IE, IO, IN

You might also like