Recall & Review
beginner
What is the purpose of the
random module in Python?The
random module helps generate random numbers and select random items, useful for simulations, games, and testing.Click to reveal answer
beginner
How do you generate a random integer between 1 and 10 inclusive in Python?
Use
random.randint(1, 10). It returns a random integer including both 1 and 10.Click to reveal answer
beginner
What function would you use to pick a random element from a list?
Use
random.choice(your_list) to select one random item from the list.Click to reveal answer
intermediate
Explain the difference between
random.random() and random.uniform(a, b).random.random() returns a float between 0.0 and 1.0 (including 0.0 but excluding 1.0). random.uniform(a, b) returns a float between a and b, including decimals.Click to reveal answer
intermediate
Why might you use
random.seed() in your program?To make random results repeatable for testing or debugging by setting a starting point for the random number generator.
Click to reveal answer
Which function generates a random integer between two numbers inclusive?
✗ Incorrect
random.randint(a, b) returns an integer between a and b, including both.What does
random.choice() do?✗ Incorrect
random.choice() picks one random item from a list or other sequence.How can you make random results repeatable in Python?
✗ Incorrect
Setting
random.seed() with a fixed number makes the random output the same every time.Which function returns a random float between 0.0 and 1.0?
✗ Incorrect
random.random() returns a float from 0.0 up to but not including 1.0.What does
random.shuffle() do to a list?✗ Incorrect
random.shuffle() changes the order of items in the list randomly without creating a new list.Describe how to generate a random integer and a random float in Python using the random module.
Think about functions for integers and floats separately.
You got /4 concepts.
Explain why and how you would use
random.seed() in your code.Consider when you want the same random output every time.
You got /4 concepts.