219k views
15 votes
Exercise 6.8.6: Totals of Lots of Rolls 5 points

Use the previous program that rolls a 6-sided die 100 times.

This time, instead of printing out the result of EACH roll, only print out the sum of the rolls for each number.

For example:

You rolled 24 ones.
You rolled 15 twos.

etc.

Write down the summary from one of the simulations to use in the next exercise.

Help plz

User P D
by
4.8k points

2 Answers

13 votes

Final answer:

To solve the problem, you would use a program that simulates rolling a six-sided die 100 times and keeps track of the total number of each result. After running the simulation, you would print out a summary of the count for each die face.

Step-by-step explanation:

The problem you're working on involves writing a program that simulates rolling a six-sided die 100 times. Rather than printing the result of each roll, you only need to print the total number of times each number was rolled. Assuming you are using a programming language like Python, you would initialize a count for each die face (1 through 6), then use a loop to roll the die 100 times, using a random number generator to simulate each roll. After the loop completes, you would print out the total counts.

Here's a simple example using Python:

import random

# Initialize counters for each die face
count_ones = 0
count_twos = 0
# ...(initialize counts for threes, fours, fives, and sixes here)

# Simulate 100 dice rolls
for _ in range(100):
roll = random.randint(1, 6)
if roll == 1:
count_ones += 1
elif roll == 2:
count_twos += 1
# ...(check and count for threes, fours, fives, and sixes here)

# Print out the totals
print(f'You rolled {count_ones} ones.')
print(f'You rolled {count_twos} twos.')
# ...(print totals for threes, fours, fives, and sixes)

In a real scenario, you would replace the counts for threes, fours, fives, and sixes similarly, and the program will give you the summary you need. Remember to record the summary to use in your next exercise.

User Alquimista
by
4.6k points
10 votes

Answer: good luck

Step-by-step explanation:

User Vasilij Nevlev
by
5.3k points