Exam-style question
Try this first
Which Python statement generates a random integer from 1 to 6 inclusive?.
- A.random.randint(1, 6)
- B.random.randint(1, 5)
- C.random.number(1, 6)
- D.random.range(1, 6)
Model answer
What a good answer should say
- random.randint(1, 6)
Explanation
Why this works
In Python, random.randint(a, b) generates an integer from a through b, including both endpoints. Therefore, random.randint(1, 6) can generate any integer from 1 to 6.
Common mistake
No common mistake is linked to this question yet.
