Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Consider a device that consists of a vertical board with evenly spaced pegs as shown below: Balls dropped from the opening at the top
1. Consider a device that consists of a vertical board with evenly spaced pegs as shown below: Balls dropped from the opening at the top of the board and move tothe left or right as they hit a peg. Aball has a 50% chance of falling to the left or right at each peg. Write a Python program, in a file called counter.py to simulate this device, asking the user for the number of balls and the number of slots in the board. Your program should output the path of each ball in the form of a string of Ls and Rs and the slot mumber that each ball falls into. Note that the slot that a ball falls into is equal to the number of "R"s in the path string. After the path of all balls have been detemined, your program should output a histogram of the slots. Divide your solution into separate functions, for example: a function to compute a path string for a ball given the number of slots (you can make use of the random function to generate random values between 0 and 1); a function to determine the slot number given a path string (do not use the count method); and a function to output a histogram. Hint Use a list to keep track of how many balls are in each slot. Sample input/output: Enter number of balls: 10 Enter number of alots: 9 Ball 0 path: RLLRRLRR in alot5 Ball 1 path: RRLRLRRR in slot 6 Ball 2 path: RRRLRLRL in slot 5 Ball 3 path: RLRLLLRL in slot 3 Ball 4 path: LLRLRLRR in slot 4 Ball 5 path: RLRRRRRL in slot 6 Ball 6 path: RLRRLLRR in slot 5 Ball 7 path: RRLRRRRL in alot6 Ball 8 path: RLRRLRLR in slot 5 Ball 9 path: LLLLLLLL in slot 0 Histogram 1. Consider a device that consists of a vertical board with evenly spaced pegs as shown below: Balls dropped from the opening at the top of the board and move tothe left or right as they hit a peg. Aball has a 50% chance of falling to the left or right at each peg. Write a Python program, in a file called counter.py to simulate this device, asking the user for the number of balls and the number of slots in the board. Your program should output the path of each ball in the form of a string of Ls and Rs and the slot mumber that each ball falls into. Note that the slot that a ball falls into is equal to the number of "R"s in the path string. After the path of all balls have been detemined, your program should output a histogram of the slots. Divide your solution into separate functions, for example: a function to compute a path string for a ball given the number of slots (you can make use of the random function to generate random values between 0 and 1); a function to determine the slot number given a path string (do not use the count method); and a function to output a histogram. Hint Use a list to keep track of how many balls are in each slot. Sample input/output: Enter number of balls: 10 Enter number of alots: 9 Ball 0 path: RLLRRLRR in alot5 Ball 1 path: RRLRLRRR in slot 6 Ball 2 path: RRRLRLRL in slot 5 Ball 3 path: RLRLLLRL in slot 3 Ball 4 path: LLRLRLRR in slot 4 Ball 5 path: RLRRRRRL in slot 6 Ball 6 path: RLRRLLRR in slot 5 Ball 7 path: RRLRRRRL in alot6 Ball 8 path: RLRRLRLR in slot 5 Ball 9 path: LLLLLLLL in slot 0 Histogram
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started