... | ... | @@ -528,7 +528,7 @@ The first three (3) lines |
|
|
limit_b = float(sys.argv[3])
|
|
|
```
|
|
|
|
|
|
grab command line arguments and parse them into `int` of `float values`.
|
|
|
grab command line arguments and parse them into `int` or `float values`.
|
|
|
|
|
|
Next... I defined a lambda function. This is the mathematical function `f(x)`
|
|
|
that will be integrated.
|
... | ... | @@ -595,6 +595,13 @@ Instead of looping over all the points |
|
|
|
|
|
the generator is assigned to a variable:
|
|
|
|
|
|
```python
|
|
|
point_sequence = generate_random_points(math_f, limit_a, limit_b, num_points)
|
|
|
```
|
|
|
|
|
|
Since we only need the `y` values from each point... an inline generator
|
|
|
expression can be used
|
|
|
|
|
|
```python
|
|
|
f_of_x_values = (y for x, y in point_sequence)
|
|
|
```
|
... | ... | @@ -607,12 +614,8 @@ This leads to a far more concise and readable computation. |
|
|
sum(f_of_x_values))
|
|
|
```
|
|
|
|
|
|
```python
|
|
|
point_sequence = generate_random_points(math_f, limit_a, limit_b, num_points)
|
|
|
```
|
|
|
---
|
|
|
|
|
|
Since we only need the `y` values from each point... an inline generator
|
|
|
expression can be used
|
|
|
|
|
|
```python
|
|
|
def main_without_a_table_flip():
|
... | ... | |