Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribed

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 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 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 number 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 determined, 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

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

=+2 Why are so many countries bothered by their brain drains?

Answered: 1 week ago