logo

Question detail

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, 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

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.

Model answer

What a good answer should say

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

Explanation

Why this works

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.

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.