00:01
Hello, for problem 19, you're asked to write a program that replicates the bean machine game.
00:10
So we're going to start by asking a user to enter a number of balls to drop, as well as a number of slots in the bean machine.
00:19
We'll call the number of balls balls and the number of slots slots.
00:23
I'm going to be using random to determine the path that the ball takes.
00:28
So i'm going to import random next.
00:31
And before i move on, i'll point out that there are lots of different ways of writing this.
00:36
So this is the way that i chose to write this program to recreate the bean machine, but there are other ways to do it.
00:45
But yes, so i imported random and now i am setting direction equal to the string lr.
00:52
The length of the boards, so the length of the path that the ball has to take will be equal to the number of slots.
01:01
And i'm going to additionally create a list called slots that is equal to the number of slots and starts out being filled with zeros.
01:13
So zero times slots.
01:16
Now for each ball, we need to determine its path.
01:19
So for ball in range balls, i'm going to set the path equal to an empty list.
01:26
And so for i in range length, where again length is length of the path, we want to append to our path list random dot choice direction.
01:37
So for each step in the path length, we want to randomly choose left or right and append that to the path.
01:45
Then we'll print out the path.
01:49
I've chosen to print using the join function so that it prints it without the brackets and commas and everything and it just prints out the letters...