Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the last part with coding the probabilityOfWinning() function the fractionGamesDecided() and averageRollsPerGame() function. I also need help on using pyplot or

image text in transcribed

I need help with the last part with coding the probabilityOfWinning() function the fractionGamesDecided() and averageRollsPerGame() function. I also need help on using pyplot or matplotlib to graph in the plotting and conclusions part.

Try it- Restart your IDLE shell, type "from random import random, seed", for tallin the result should repeatedly call playOneGame ( ) and increment the appropriate umber of wins or losses for the umber of throws retumed. and then call seed () with your mame as its This data structuces need to be open-ended. Although most games may iniswithin, say, a dozen throws, some games may go for 20, 30, or more throus before recording a win or a loss. If you use an open-ended structure such as a ist,ywould be able to grow it if an unusually long game occurs. Of course, the intervening counts of wins and losses would be set to zero. Next, call random () multiple times and note the values retuned. The rrambers still look a random sequence Now, sestart the shell and call seed () again with your nanee as argument, exactly as before. Next, call random () multiple times again You should see that the sequence of umbers is exactly the same as the previous time. Trv this also for randrange () Plot and comchusions Once the simulation has been run for using pyplot/matplotlib. The wasis ralues should represent numbers of throws needed to complete each game. The ais should have two lines- many, many games, the results should be plotted on a Your program Your program for this assigment should consist of at least t pimary modules- one for playing the game of craps and a separate one for keeping statistics and answecing questions. You must also have a third module that serves as a "wrapper" for controlling the program and helping to test it. The sene' sb sa metr the 00er: This keeps it separate from the simulation itself. the percentage efthe totalma mier e games that terminate in a win versus # of throws, and . the percentage f the total msmethat terminate in a loss veus number of thos. Save your graph to a Ele by cicking on the Save button at the bottom of the maploit window. Most graphs ase saved in png format Graph names should start with yous Camas team name or your WPI username. Be sure to submit your graph(s) along with your README file as described below. Piging tbeae The function playOneGame) should do exactily that roll the pair of dice as many times as necessary to win or lose Each roll of the dice is simulated by tato randrange (1,7), one for each die' This function retuens the number of spots on the face of one die. Do the same for the othes die, and then add them together to get the result of the roll Apply this result to the rules of the game to determine whether rou have won, lost, or continue playing. README documeent and speafi gwetios You must also prepare include a shoxt document in .txt, pdf, .doc, or .docx fomat called README. In this document, you must Describe the data structure used to accumulate the results of playing many games, and Summarize your conclusions about what the graphs tell you about the game of Craps. In particular, you must anse the following questions from the Lecture Notes- When the game is either won or lost after a number of olls, the playOneGame ) function should retuen u values-a True/Palse value indicatingwhethes the game was won or lost True means won) and an integer indicating the mumber of rolls. What is the probablity that player wins eventually wins? What fraction of games are decided on 1 roll? 2 roll 3 rolP etc? Note: Retucning multiple values from a function is just Else Simeuiameos Asaigemeet as described in $2.5.3 of the textbook. That is, the return statement can take a set of values separated by commas. These can be assigned to an equal rumber of the is average rumber of rolls per game? Yous statistics module must contain at least three functions-one for each of these questions that produces the answer for that questions. These functions should be variables on the left side of an assignment in probabilityOfWinning ( ) This should retun a number between 0 and 1 that indicates the probability as determined by vour smulation. fractionGamesDecided().This should retun a ist of numbers, each one being between zero and one. The ithnumber in the list should indicate the fraction of games that were won or lost in exacty i throws averageRollsPerGame (). This should retun a number that is the average G.e. arithmetic mean) of the umber of rolls per game in Tous simulation. The playOneGame) function, along with any supporting functions, should be defined in the module for playing the game. You may name this module whatever you like. 9 Kreping track oftbel A function for talying the results should be defined in the module for keeping statisties. You may name this module wihaterer you lke. In previous terms, tallyResults was often used. This module and the fanction for tallying the zesults should have one parameter that specifies the number of games to play. This function must maintain two data structures-one for wins and one for losses. These indicate the number of games won or lost by the number of thros The function You may include other functions as necessary for youe program design. It you ase ambitious,u may seDiaRead S11.6 in the textbook to lean about dietionaes ini Dor't be tempted to combine the rolls of both dice into a single call to random) The distnibutions of the mndom numbers all not bethe same as ifyond roltd two dioe independenty Note that png files can become quite le. The png fomat is suitable for this assigment, but in futrue signmeuts yoa ma hare to convert to jpgnoder to keep theze mangable Try it- Restart your IDLE shell, type "from random import random, seed", for tallin the result should repeatedly call playOneGame ( ) and increment the appropriate umber of wins or losses for the umber of throws retumed. and then call seed () with your mame as its This data structuces need to be open-ended. Although most games may iniswithin, say, a dozen throws, some games may go for 20, 30, or more throus before recording a win or a loss. If you use an open-ended structure such as a ist,ywould be able to grow it if an unusually long game occurs. Of course, the intervening counts of wins and losses would be set to zero. Next, call random () multiple times and note the values retuned. The rrambers still look a random sequence Now, sestart the shell and call seed () again with your nanee as argument, exactly as before. Next, call random () multiple times again You should see that the sequence of umbers is exactly the same as the previous time. Trv this also for randrange () Plot and comchusions Once the simulation has been run for using pyplot/matplotlib. The wasis ralues should represent numbers of throws needed to complete each game. The ais should have two lines- many, many games, the results should be plotted on a Your program Your program for this assigment should consist of at least t pimary modules- one for playing the game of craps and a separate one for keeping statistics and answecing questions. You must also have a third module that serves as a "wrapper" for controlling the program and helping to test it. The sene' sb sa metr the 00er: This keeps it separate from the simulation itself. the percentage efthe totalma mier e games that terminate in a win versus # of throws, and . the percentage f the total msmethat terminate in a loss veus number of thos. Save your graph to a Ele by cicking on the Save button at the bottom of the maploit window. Most graphs ase saved in png format Graph names should start with yous Camas team name or your WPI username. Be sure to submit your graph(s) along with your README file as described below. Piging tbeae The function playOneGame) should do exactily that roll the pair of dice as many times as necessary to win or lose Each roll of the dice is simulated by tato randrange (1,7), one for each die' This function retuens the number of spots on the face of one die. Do the same for the othes die, and then add them together to get the result of the roll Apply this result to the rules of the game to determine whether rou have won, lost, or continue playing. README documeent and speafi gwetios You must also prepare include a shoxt document in .txt, pdf, .doc, or .docx fomat called README. In this document, you must Describe the data structure used to accumulate the results of playing many games, and Summarize your conclusions about what the graphs tell you about the game of Craps. In particular, you must anse the following questions from the Lecture Notes- When the game is either won or lost after a number of olls, the playOneGame ) function should retuen u values-a True/Palse value indicatingwhethes the game was won or lost True means won) and an integer indicating the mumber of rolls. What is the probablity that player wins eventually wins? What fraction of games are decided on 1 roll? 2 roll 3 rolP etc? Note: Retucning multiple values from a function is just Else Simeuiameos Asaigemeet as described in $2.5.3 of the textbook. That is, the return statement can take a set of values separated by commas. These can be assigned to an equal rumber of the is average rumber of rolls per game? Yous statistics module must contain at least three functions-one for each of these questions that produces the answer for that questions. These functions should be variables on the left side of an assignment in probabilityOfWinning ( ) This should retun a number between 0 and 1 that indicates the probability as determined by vour smulation. fractionGamesDecided().This should retun a ist of numbers, each one being between zero and one. The ithnumber in the list should indicate the fraction of games that were won or lost in exacty i throws averageRollsPerGame (). This should retun a number that is the average G.e. arithmetic mean) of the umber of rolls per game in Tous simulation. The playOneGame) function, along with any supporting functions, should be defined in the module for playing the game. You may name this module whatever you like. 9 Kreping track oftbel A function for talying the results should be defined in the module for keeping statisties. You may name this module wihaterer you lke. In previous terms, tallyResults was often used. This module and the fanction for tallying the zesults should have one parameter that specifies the number of games to play. This function must maintain two data structures-one for wins and one for losses. These indicate the number of games won or lost by the number of thros The function You may include other functions as necessary for youe program design. It you ase ambitious,u may seDiaRead S11.6 in the textbook to lean about dietionaes ini Dor't be tempted to combine the rolls of both dice into a single call to random) The distnibutions of the mndom numbers all not bethe same as ifyond roltd two dioe independenty Note that png files can become quite le. The png fomat is suitable for this assigment, but in futrue signmeuts yoa ma hare to convert to jpgnoder to keep theze mangable

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

Using Language That Works

Answered: 1 week ago

Question

1. Define the nature of interviews

Answered: 1 week ago

Question

=+what kinds of policies and practices should be developed?

Answered: 1 week ago