CSCI 107 Assignment 6


Dice Rolling Simulation

The purpose of this assignment is to help you gain experience using while loops, for loops, functions and if statements when solving problems.

For this assignment, you will write a program to estimate the probability of winning a dice rolling game by simulating the game. The user is queried for (1) the number of times the simulation should run, (2) the value of the winning sum, (3) the number of dice that will be rolled each time, and (4) how many sides each of these dice has. You may assume that if a die has n sides, that the sides are numbered 1 through n and that rolling each number is equally likely. You may also assume that the user will enter a valid positive integer for each of the four requested inputs.

During one simulation, if the running total (that always starts at 0) matches the winning sum, the game is won. If the running total exceeds the winning sum, the game is lost. Otherwise, the dice are rolled again and the sum of the new roll is added to the running total.

Example (trials: 2, winning sum: 10, number of dice: 2, sides per die: 6)

Trial 1

Trial 2

Sample Output Transcript

This transcript shows three runs of the program.

Requirements and Grading

Download and rename assignment6.py according to the instructions above. Do not modify the provided main function.

Test Data