Today we will learn about the 3 useful features of the random library
First we need to import random
Now let's look at the first features
Choosing a random integer
Example :-
import random
number = random.randint(0,100)
print(number)
We could improve it a little bit Example :-
Moving on , let's look at randomly choosing o. Item import random
max_number = int(input("choose a # between 0 and..."))
number= random.randint(0,max_number)
print(number)
Example :-
import random
basket = ("apple","banana","mango","orange","grapes")
chosen_fruit = random.choice(basket)
print(chosen_fruit)
lastly, let's look at the shuffle option . We will keep the basket Example :-
import random
basket = ["apple","mango","banana","grapes"]
print(basket)
print("Now shuffling the order of the basket...")
random.shuffle(basket)
print(basket)
0 Comments