logo

AQA A-Level Computer Science practice

Which Python program fragment correctly generates and displays a random integer from 1 to 10 inclusive?

Try the question first, then check the answer and practise the same topic again.

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)

Answer and explanation

Concise answer

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

Why this is correct

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.

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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions