Pseudo
Pseudo
Random module
Practical Part
Problem1
import random
print("Generating 3 random integer number between 100 and 999 divisible by 5")
for num in range(3):
print(random.randrange(100, 999, 5), end=', ')
• Exercise 2: Random Lottery Pick. Generate 100 random
lottery tickets and pick two lucky tickets from it as a
winner.
import random
lottery_tickets_list = []
print("creating 100 random lottery tickets")
# to get 100 ticket
for i in range(100):
# ticket number must be 10 digit (1000000000, 9999999999)
lottery_tickets_list.append(random.randrange(1000000000, 9999999999))
# pick 2 luck tickets
winners = random.sample(lottery_tickets_list, 2)
print("Lucky 2 lottery tickets are", winners)
• Exercise 4: Pick a random character from a given String
import random
name = 'pynative'
char = random.choice(name)
print("random char is ", char)
• Exercise 9: Roll dice in such a way that every time you
get the same number
• Dice has 6 numbers (from 1 to 6). Roll dice in such a way
that every time you must get the same output number. do
this 5 times.
import random
dice = [1, 2, 3, 4, 5, 6]
print("Randomly selecting same number of a dice")
for i in range(5):
random.seed(25)
print(random.choice(dice))
Exercise 1