GitHub

@@ -595,11 +595,10 @@ all([1 <= 2 <= 3, "a" in "letter"])

595595

any([1 <= 2 <= 3, "a" in "letter"])

596596

```

597597598-

Note:

599-598+

```{note}

600599

* `all()` returns `True` when *all* boolean values/expressions in the sequence are `True`

601600

* `any()` returns `True` when *any* boolean values/expressions in the sequence are `True`

602-601+

```

603602604603

## Coding Style and Documentation

605604

@@ -692,20 +691,28 @@ Solve the following exercises.

692691693692

(For some, the built-in function `sum()` comes in handy).

694693695-

```{exercise}

694+

```{exercise-start}

696695

:label: pyess_ex1

697-696+

```

698697

Part 1: Given two numeric lists or tuples `x_vals` and `y_vals` of equal length, compute

699698

their inner product using `zip()`.

700699701700

Part 2: In one line, count the number of even numbers in 0,...,99.

702701703-

* Hint: `x % 2` returns 0 if `x` is even, 1 otherwise.

704-705702

Part 3: Given `pairs = ((2, 5), (4, 2), (9, 8), (12, 10))`, count the number of pairs `(a, b)`

706703

such that both `a` and `b` are even.

704+705+

```{hint}

706+

:class: dropdown

707+708+

`x % 2` returns 0 if `x` is even, 1 otherwise.

709+707710

```

708711712+

```{exercise-end}

713+

```

714+715+709716

```{solution-start} pyess_ex1

710717

:class: dropdown

711718

```

@@ -804,12 +811,20 @@ p(1, (2, 4))

804811

```

805812806813807-

```{exercise}

814+

```{exercise-start}

808815

:label: pyess_ex3

816+

```

809817810818

Write a function that takes a string as an argument and returns the number of capital letters in the string.

811819812-

Hint: `'foo'.upper()` returns `'FOO'`.

820+

```{hint}

821+

:class: dropdown

822+823+

`'foo'.upper()` returns `'FOO'`.

824+825+

```

826+827+

```{exercise-end}

813828

```

814829815830

```{solution-start} pyess_ex3

Read the original on github.com ↗