diff --git a/concepts/none/about.md b/concepts/none/about.md index 79ac4c2a08d..157f1d3a41b 100644 --- a/concepts/none/about.md +++ b/concepts/none/about.md @@ -1,2 +1,3 @@ -# About +# TODO: Add about for this concept. + diff --git a/concepts/none/introduction.md b/concepts/none/introduction.md index 724413a1118..1f3c3ccf3d6 100644 --- a/concepts/none/introduction.md +++ b/concepts/none/introduction.md @@ -1,29 +1,33 @@ # Introduction -In Python, `None` is frequently used to represent the absence of a value -- a placeholder to define a `null` (empty) variable, object, or argument. +In Python, `None` is frequently used to represent the absence of a value — a placeholder to define a `null` (empty) variable, object, or argument. + +If you've heard about or used a `NULL` or `nil` type in another programming language, then this usage of `None` in Python will be familiar to you. +`None` helps you to declare variables or function arguments that you don't yet have values for. +These can then be re-assigned to specific values later as needed: -If you've heard about or used a `NULL` or `nil` type in another programming language, then this usage of `None` in Python will be familiar to you. `None` helps you to declare variables or function arguments that you don't yet have values for. These can then be re-assigned to specific values later as needed. ```python a = None print(a) #=> None + type(a) #=> -# Adding a Default Argument with `None` +# Adding a default argument with `None` def add_to_todos(new_task, todo_list=None): - if todo_list is None: - todo_list = [] + if todo_list is None: + todo_list = [] todo_list.append(new_task) + return todo_list - ``` -`None` will evaluate to `False` when used in a conditional check, so it is useful for validating the "presence of" or "absence of" a value - _any_ value -- a pattern frequently used when a function or process might hand back an error object or message. +`None` will evaluate to `False` when used in a conditional check, so it is useful for validating the "presence of" or "absence of" a value — _any_ value — a pattern frequently used when a function or process might hand back an `error`, `object`, or message. ```python a = None -if a: #=> a will be evaluated to False when its used in a conditional check. +if a: #<-- a will be evaluated to False when it is used in a conditional check. print("This will not be printed") ``` diff --git a/concepts/random/about.md b/concepts/random/about.md index 9ed984179d3..54478addb15 100644 --- a/concepts/random/about.md +++ b/concepts/random/about.md @@ -1,9 +1,9 @@ # About -Many programs need (apparently) random values to simulate real-world events. +Many programs need (_seemingly_) random values to simulate real-world events. Common, familiar examples include: -- A coin toss: a random value from `('H', 'T')`. +- A coin toss: a random value from `('Heads', 'Tails')`. - The roll of a die: a random integer from 1 to 6. - Shuffling a deck of cards: a random ordering of a card list. @@ -18,7 +18,7 @@ We encourage you to explore the full `random` documentation, as there are many m ~~~~exercism/caution -The `random` module should __NOT__ be used for security and cryptographic applications. +The `random` module should __NOT__ be used for security or cryptographic applications. Instead, Python provides the [`secrets`][secrets] module. This is specially optimized for cryptographic security. @@ -60,8 +60,8 @@ To avoid typing the name of the module, you can import specific functions by nam # Using choice() to pick Heads or Tails 10 times >>> tosses = [] ->>> for side in range(10): ->>> tosses.append(choice(['H', 'T'])) +... for side in range(10): +... tosses.append(choice(['H', 'T'])) >>> print(tosses) ['H', 'H', 'H', 'H', 'H', 'H', 'H', 'T', 'T', 'H'] @@ -69,8 +69,8 @@ To avoid typing the name of the module, you can import specific functions by nam # Using choices() to pick Heads or Tails 8 times >>> picks = [] ->>> picks.extend(choices(['H', 'T'], k=8)) ->>> print(picks) +... picks.extend(choices(['H', 'T'], k=8)) +... print(picks) ['T', 'H', 'H', 'T', 'H', 'H', 'T', 'T'] ``` @@ -94,8 +94,9 @@ Possible results from `randint()` _include_ the upper bound, so `randint(a, b)` # Select 10 numbers at random between 0 and 9 two steps apart. >>> numbers = [] ->>> for integer in range(10): ->>> numbers.append(random.randrange(0, 10, 2)) +... for integer in range(10): +... numbers.append(random.randrange(0, 10, 2)) + >>> print(numbers) [2, 8, 4, 0, 4, 2, 6, 6, 8, 8] @@ -108,10 +109,10 @@ Possible results from `randint()` _include_ the upper bound, so `randint(a, b)` ## Working with sequences -The functions in this section assume that you are starting from some [sequence][sequence-types], or other container. +The functions in this section assume that you are starting from some [sequence][sequence-types] or other container. -This will typically be a `list`, or with some limitations a `tuple` or a `set` (_a `tuple` is immutable, and `set` is unordered_). +This will typically be a `list`, or with some limitations, a `tuple` or a `set` (_a `tuple` is immutable, and `set` is unordered_). @@ -124,9 +125,10 @@ At its simplest, this might be a coin-flip: # This will pick one of the two values in the list at random 5 separate times >>> [random.choice(['H', 'T']) for _ in range(5)] ['T', 'H', 'H', 'T', 'H'] +``` -We could accomplish essentially the same thing using the `choices()` function, supplying a keyword argument with the list length: +We could accomplish essentially the same thing using the `choices()` function, supplying a keyword argument with the list length: ```python >>> random.choices(['H', 'T'], k=5) diff --git a/concepts/random/introduction.md b/concepts/random/introduction.md index 6bf880be57f..164a0e4202f 100644 --- a/concepts/random/introduction.md +++ b/concepts/random/introduction.md @@ -1,9 +1,9 @@ # Introduction -Many programs need (apparently) random values to simulate real-world events. +Many programs need (_seemingly_) random values to simulate real-world events. Common, familiar examples include: -- A coin toss: a random value from `('H', 'T')`. +- A coin toss: a random value from `('Heads', 'Tails')`. - The roll of a die: a random integer from 1 to 6. - Shuffling a deck of cards: a random ordering of a card list. - The creation of trees and bushes in a 3-D graphics simulation. @@ -18,7 +18,7 @@ We encourage you to explore the full [`random`][random] documentation, as there ~~~~exercism/caution -The `random` module should __NOT__ be used for security and cryptographic applications!! +The `random` module should __NOT__ be used for security or cryptographic applications!! Instead, Python provides the [`secrets`][secrets] module. This is specially optimized for cryptographic security. @@ -57,8 +57,8 @@ To avoid typing the name of the module, you can import specific functions by nam # Using choice() to pick Heads or Tails 10 times >>> tosses = [] ->>> for side in range(10): ->>> tosses.append(choice(['H', 'T'])) +... for side in range(10): +... tosses.append(choice(['H', 'T'])) >>> print(tosses) ['H', 'H', 'H', 'H', 'H', 'H', 'H', 'T', 'T', 'H'] @@ -66,8 +66,8 @@ To avoid typing the name of the module, you can import specific functions by nam # Using choices() to pick Heads or Tails 8 times >>> picks = [] ->>> picks.extend(choices(['H', 'T'], k=8)) ->>> print(picks) +... picks.extend(choices(['H', 'T'], k=8)) +... print(picks) ['T', 'H', 'H', 'T', 'H', 'H', 'T', 'T'] ``` @@ -89,10 +89,10 @@ Possible results from `randint()` _include_ the upper bound, so `randint(a, b)` ## `choice()` and `choices()` -These two functions assume that you are starting from some [sequence][sequence-types], or other container. -This will typically be a `list`, or with some limitations a `tuple` or a `set` (_a `tuple` is immutable, and `set` is unordered_). +These two functions assume that you are starting from some [sequence][sequence-types] or other container. +This will typically be a `list`, or with some limitations, a `tuple` or a `set` (_a `tuple` is immutable, and `set` is unordered_). -The `choice()` function will return one entry chosen at random from a given sequence, and `choices()` will return `k` number of entries chosen at random from a given sequence. +The `choice()` function will return one member chosen at random from a given sequence, and `choices()` will return a specified number of members (`k`) chosen at random from a given sequence. In the examples shown above, we assumed a fair coin with equal probability of heads or tails, but weights can also be specified. For example, if a bag contains 10 red balls and 15 green balls, and we would like to pull one out at random: