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)
Answer and explanation
Concise answer
random.randint(1, 6)
Why this is correct
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.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
