Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that performs a simulation to estimate the probability of rollin

ID: 3936256 • Letter: W

Question

Write a program that performs a simulation to estimate the probability of rolling five-of-a-kind in single roll of five six-sided dice. Use top-down design, and bottom up implementation. Use functions; define functions that only do one thing (and can be described without the word "and"). Document each function with a one-sentence description. Allow the user to specify how many rolls are simulated. Optimize your code by removing all print statements and extraneous calculations during the simulation. Python Validate the input to be sure the program terminates within ten seconds. (E.g. measure how many simulations can be done in ten seconds, and restrict input to that amount).

Explanation / Answer

from random import randrange

def main():

printIntro()

times = getInput()

foak = rollNtimes(times)

printsummary(foak,times)

def printIntro():

print(' ' ' A Dice Simulation to check probability to getting five of a kind in single roll,' ' ')

def getInput():

times = eval(input(' how many times you want to roll the dices: '))

return times

def rollNtimes(times):

foak= 0

for i in range(times):

result= rollOneTime()

foak = diceCheck(result,foak)

return foak

def rollOneTime():

result = 'no'

i = 0

x = diceRandom()

while diceRandom() == x:

i = i+1

if i == 4:

result = 'yes'

return result

def diceCheck(result,foak):

if result == 'yes':

foak = foak+1

return foak

def diceRandom():

x = randrange(1,7)

return x

def printSummary(foak,times):

print(' For {} times we get FOAK {} which is {:0.2%}'. format(times,foak,foak/times))

if __ name__=='__main__' : main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote