Study Guide

4.9.5 Lots of Dice CodeHS Answers

4.9.5 Lots of Dice CodeHS Answers

The most common answer is:

import random
for i in range(100): [print(random.randint(1,6))]
Enter your code here

This code aims to simulate rolling a six-sided die 100 times and print the result of each roll. However, the syntax for the loop and print statement needs a slight adjustment for proper execution. Here’s the corrected version:

import random

for i in range(100):
    print(random.randint(1, 6))

This code will correctly print a random number between 1 and 6 (inclusive), simulating the outcome of rolling a die, for each of the 100 iterations.