logo

Question detail

Which Python program fragment correctly generates and displays a random integer from 1 to 10 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 program fragment correctly generates and displays a random integer from 1 to 10 inclusive?.

  1. A.import random number = random.randint(1, 10) print(number)
  2. B.import random number = random.randint(1, 9) print(number)
  3. C.import random number = random.randint(0, 10) print(number)
  4. D.import random number = random.integer(1, 10) print(number)

Model answer

What a good answer should say

  • import random number = random.randint(1, 10) print(number)

Explanation

Why this works

The random module is imported, randint is used with the inclusive limits 1 and 10, and the generated value is displayed. The other options use an incorrect range or an incorrect function name.

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.