mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
chore(curriculum): Python Probabillity Calculator add quotes to strings (#55434)
This commit is contained in:
+3
-3
@@ -20,14 +20,14 @@ hat2 = Hat(red=5, orange=4)
|
||||
hat3 = Hat(red=5, orange=4, black=1, blue=0, pink=2, striped=9)
|
||||
```
|
||||
|
||||
A hat will always be created with at least one ball. The arguments passed into the hat object upon creation should be converted to a `contents` instance variable. `contents` should be a list of strings containing one item for each ball in the hat. Each item in the list should be a color name representing a single ball of that color. For example, if your hat is `{"red": 2, "blue": 1}`, `contents` should be `["red", "red", "blue"]`.
|
||||
A hat will always be created with at least one ball. The arguments passed into the hat object upon creation should be converted to a `contents` instance variable. `contents` should be a list of strings containing one item for each ball in the hat. Each item in the list should be a color name representing a single ball of that color. For example, if your hat is `{'red': 2, 'blue': 1}`, `contents` should be `['red', 'red', 'blue']`.
|
||||
|
||||
The `Hat` class should have a `draw` method that accepts an argument indicating the number of balls to draw from the hat. This method should remove balls at random from `contents` and return those balls as a list of strings. The balls should not go back into the hat during the draw, similar to an urn experiment without replacement. If the number of balls to draw exceeds the available quantity, return all the balls.
|
||||
|
||||
Next, create an `experiment` function in `main.py` (not inside the `Hat` class). This function should accept the following arguments:
|
||||
|
||||
- `hat`: A hat object containing balls that should be copied inside the function.
|
||||
- `expected_balls`: An object indicating the exact group of balls to attempt to draw from the hat for the experiment. For example, to determine the probability of drawing 2 blue balls and 1 red ball from the hat, set `expected_balls` to `{"blue":2, "red":1}`.
|
||||
- `expected_balls`: An object indicating the exact group of balls to attempt to draw from the hat for the experiment. For example, to determine the probability of drawing 2 blue balls and 1 red ball from the hat, set `expected_balls` to `{'blue':2, 'red':1}`.
|
||||
- `num_balls_drawn`: The number of balls to draw out of the hat in each experiment.
|
||||
- `num_experiments`: The number of experiments to perform. (The more experiments performed, the more accurate the approximate probability will be.)
|
||||
|
||||
@@ -40,7 +40,7 @@ Here is how you would call the `experiment` function based on the example above
|
||||
```py
|
||||
hat = Hat(black=6, red=4, green=3)
|
||||
probability = experiment(hat=hat,
|
||||
expected_balls={"red":2,"green":1},
|
||||
expected_balls={'red':2,'green':1},
|
||||
num_balls_drawn=5,
|
||||
num_experiments=2000)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user