logo

AQA A-Level Computer Science practice

A program must generate five random integers, each from 10 to 20 inclusive, and display each integer. Write suitable Python code and explain how the range of generated values is controlled.

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

At a glance

Question

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

A program must generate five random integers, each from 10 to 20 inclusive, and display each integer. Write suitable Python code and explain how the range of generated values is controlled.

Answer and explanation

Concise answer

import random for count in range(5): value = random.randint(10, 20) print(value)

Why this is correct

The loop repeats five times, so five values are generated and displayed. Each call to random.randint(10, 20) produces an integer whose lower and upper limits are both included. Therefore, every displayed value is from 10 through 20 inclusive.

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