Here
Here
request:
Definition:
A random function generates unpredictable outputs, commonly used in simulations, games,
and testing.
Key Features:
o Offers a variety of functions for specific use cases (e.g., integers, floats, list
elements).
import random
Applications:
Example Program:
import random
Slide 6: Question 1
Question:
What will random.randint(1, 5) return?
Options:
Answer:
(C) Any integer between 1 and 5.
Explanation:
The randint() function includes both boundaries, so the possible outputs are 1, 2, 3, 4, or 5.
Slide 7: Question 2
Question:
What will the following code output?
import random
Options:
(A) apple
(B) banana
(C) cherry
Answer:
(D) Any one of the above.
Explanation:
The choice() function randomly selects one element from the list, so the output can be either apple,
banana, or cherry.
Slide 8: Question 3
Question:
Which function generates a random float between two numbers, aa and bb?
Options:
(A) random()
(B) randint(a, b)
(C) uniform(a, b)
(D) shuffle()
Answer:
(C) uniform(a, b)
Explanation:
The uniform(a, b) function generates a random float within the range [a,b][a, b], including the
boundaries.
Animation: Explanation fades in at the bottom.
Slide 9: Question 4
Question:
What will random.shuffle() do to a list?
Options:
Answer:
(C) Rearrange the list in random order.
Explanation:
The shuffle() function rearranges the elements of the list randomly. It modifies the list in place.
Question:
What will random.random() return?
Options:
Answer:
(A) A random float between 0 and 1.
Let me know if you'd like me to create this PowerPoint file for you!