logo

AQA A-Level Computer Science practice

Write a Python program that simulates rolling a six-sided die once. The program must generate a random integer from 1 to 6 inclusive and display the result. Explain how your program meets the requirements.

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

Write a Python program that simulates rolling a six-sided die once. The program must generate a random integer from 1 to 6 inclusive and display the result. Explain how your program meets the requirements.

Answer and explanation

Concise answer

import random roll = random.randint(1, 6) print(roll)

Why this is correct

The random module is imported so that random number generation can be used. randint(1, 6) generates an integer with 1 and 6 included in the possible range, representing the result of one six-sided die roll. The print statement displays the generated result.

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