logo

Question detail

Which Python statement generates a random integer from 1 to 6 inclusive?

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

MCQ

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

Which Python statement generates a random integer from 1 to 6 inclusive?.

  1. A.random.randint(1, 6)
  2. B.random.randint(1, 5)
  3. C.random.number(1, 6)
  4. 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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.