Write a program that animates the bean machine introduced in Programming Exercise

Write a program that animates the bean machine introduced in Programming Exercise 7.37. The animation terminates
after 10 balls are dropped, as shown in Figures 15.38b and c.

Data from Programming Exercise 7.37. 

The bean machine, also known as a quincunx or the Galton
box, is a device for statistics experiments named after English scientist Sir
Francis Galton. It consists of an upright board with evenly spaced nails (or pegs)
in a triangular form, as shown in Figure 7.13.

Balls are dropped from the opening of the board. Every time a ball hits a nail, it has a 50% chance of falling to the left or to the right. The piles of balls are accumulated in the slots at the bottom of the board. Write a program that simulates the bean machine. Your program should prompt the user to enter the number of the balls and the number of the slots in the machine. Simulate the falling of each ball by printing its path. For example, the path for the ball in Figure 7.13b is LLRRLLR and the path for the ball in Figure 7.13c is RLRRLRR. Display the final buildup of the balls in the slots in a histogram. Here is a sample run of the program: 

How Our Website Works


It has never been easier to place your order. Fill in the initial requirements in the small order form located on the home page and press “continue” button to proceed to the main order form or press “order” button in the header menu. Starting from there let our system intuitively guide you through all steps of ordering process.


All your payments are processed securely through PayPal. This enables us to guarantee a 100% security of your funds and process payments swiftly.


Next, we match up your order details with the most qualified freelance writer in your field.


Once we have found the most suitable writer for your assignment, they start working on a masterpiece just for you!


Once finished, your final paper will be available for download through your personal dashboard. You will also receive an email notification with a copy of your paper attached to it. Sometimes, the writer may leave a note for you about the order in case there is any additional information that they need to give you.

Leave a Reply

Your email address will not be published.