CBSE COMPUTER SCIENCE
前往频道在 Telegram
QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1
显示更多549
订阅者
无数据24 小时
无数据7 天
无数据30 天
帖子存档
0.345100276374246
16.022778163937048
13.953156530132006
9.92250007349345
2
3
Before Shuffled : [1, 2, 3, 7, 10, 'Apple', 'Mango', 55, 75.23]
After Shuffled : [1, 'Mango', 2, 3, 75.23, 'Apple', 55, 10, 7]
Given Sequence : [1, 2, 3, 7, 10, 'Apple', 'Mango', 55, 75.23]
Choosen the element : Apple
import random
#L-Lower Limit, U-Upper Limit
#random.random() : Returns a floating point value between 0 and 1.
#0 and 1 are not included Ex. 0.1 to 0.999
#A number between 0 and 1
num = random.random()
print(num)
#A number between 0 and 50
num = random.random() * 50
print(num)
# A number between -50(L) and 50(U)
num = random.random() * 100 - 50
print(num)
#random.uniform(L,U): Returns floating point value between L and U.
#L included and U may or may not be included
# A floating point number between 1 and 10
num = random.uniform(1,10)
print(num)
#lower(L) limit (0) included, upper(U) limit excluded
num=random.randrange(10)
print(num)
#random.randint(L,U) -
#Returns an integer between U and L.
#Both lower(L) limit and upper(U) limit Included
# An Integer number between 1 and 10
num=random.randint(1,10)
print(num)
#Random functions for a Sequence
#Methods 1 : random.shuffle(Sequence)
L=[1,2,3,7,10,'Apple','Mango',55,75.23]
print("Before Shuffled : ",L)
random.shuffle(L)
print("After Shuffled : ",L)
#Methods 2 : random.choice(Sequence)
L=[1,2,3,7,10,'Apple','Mango',55,75.23]
print("Given Sequence : ",L)
K=random.choice(L)
print("Choosen the element : ",K)
