Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 to the left or right as they hit a peg. A ball 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 simulatethis device, asking the user for the nmber 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 number that each ball falls into. Note that the slot that a ball falls into is equal to the number of "Rs in the path string. After the path of all balls have been determined, your program should output a histogram of the slot 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 randon 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 nunber of slots: 9 Ball 0 path RLLRRLRR in slot 5 Ball 1 path RRLRIRRR 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 alot 6 Ball 6 path RLRRLLRR in alot 5 Ball 7 path: RRLRRRRL in slot 6 Ball 8 path: RLRRLRLR in slot 5 Ball 9 path: LLLLLLLL in slot 0 Histogran 0 oo00

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

How would you describe your typical day at work?

Answered: 1 week ago

Question

2. Write two or three of your greatest weaknesses.

Answered: 1 week ago