logo

Question detail

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, check the answer, then read the explanation to understand the curriculum point.

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.

Model answer

What a good answer should say

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

Explanation

Why this works

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.

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.