python_practicals
python_practicals
Code:
import random
Output:
Code:
import random
random_float = random.random()
Output:
Code:
import random
items = ['apple', 'banana', 'cherry', 'date']
random_item = random.choice(items)
Output:
Code:
import random
numbers = [1, 2, 3, 4, 5]
random.shuffle(numbers)
Output:
Code:
import random
numbers = [10, 20, 30, 40, 50, 60, 70, 80, 90]
random_sample = random.sample(numbers, 3)
Output:
Aim: Write a program to generate a random number within a specified range and with a given step.
Code:
import random
Output:
Aim: Write a program to generate a random floating-point number within a given range.
Code:
import random
Output:
Aim: Write a program to set a random seed and generate reproducible random numbers.
Code:
import random
random.seed(10)
Output: