diff --git a/concepts/loops/about.md b/concepts/loops/about.md index 0f39e733d0c..e3322af0e3b 100644 --- a/concepts/loops/about.md +++ b/concepts/loops/about.md @@ -31,7 +31,6 @@ The keywords `break`, `continue`, and `else` help customize loop behavior. The basic [`for`][for statement] `loop` in Python is better described as a _`for each`_ which cycles through the values of any [iterable object][iterable], terminating when there are no values returned from calling [`next()`][next built-in] (_raising a [`StopIteration`][stopiteration]_). ```python - >>> word_list = ["bird", "chicken", "barrel", "bongo"] >>> for word in word_list: @@ -95,7 +94,6 @@ Interestingly, `range()` [_is not an iterator_][range is not an iterator], and c If both values and indexes are needed, the built-in [`enumerate()`][enumerate] will return an [`iterator`][iterator] over (`index`, `value`) pairs: ```python - >>> word_list = ["bird", "chicken", "barrel", "apple"] # *index* and *word* are the loop variables. @@ -152,15 +150,15 @@ The `enumerate()` function can also be set to `start` the index count The [`continue`][continue statement] keyword can be used to skip forward to the next iteration cycle: ```python -word_list = ["bird", "chicken", "barrel", "bongo", "sliver", "apple", "bear"] - -# This will skip *bird*, at index 0 -for index, word in enumerate(word_list): - if index == 0: - continue - if word.startswith("b"): - print(f"{word.title()} (at index {index}) starts with a b.") - +>>> word_list = ["bird", "chicken", "barrel", "bongo", "sliver", "apple", "bear"] +... +... # This will skip *bird*, at index 0 +... for index, word in enumerate(word_list): +... if index == 0: +... continue +... if word.startswith("b"): +... print(f"{word.title()} (at index {index}) starts with a b.") +... 'Barrel (at index 2) starts with a b.' 'Bongo (at index 3) starts with a b.' 'Bear (at index 6) starts with a b.' @@ -176,9 +174,9 @@ The [`break`][break statement] (_like in many C-related languages_) keyword can ... if word.startswith("b"): ... print(f"{word.title()} (at index {index}) starts with a B.") ... elif word == "sliver": -... break +... break ... else: -... print(f"{word.title()} doesn't start with a B.") +... print(f"{word.title()} doesn't start with a B.") ... print("loop broken.") ... 'Bird (at index 0) starts with a B.' @@ -202,11 +200,11 @@ The loop [`else` clause][loop else] is unique to Python and can be used for "wra ... word = word.title() ... if word.startswith("B"): ... print(f"{word} (at index {index}) starts with a B.") - -...# This executes once *StopIteration* is raised and -...# there are no more items to iterate through. -...# Note the indentation, which lines up with the for keyword. -...else: +... +... # This executes once *StopIteration* is raised and +... # There are no more items to iterate through. +... # Note the indentation, which lines up with the for keyword. +... else: ... print(f"Found the above b-words, out of {len(word_list)} words in the word list.") ... 'Bird (at index 0) starts with a B.' @@ -227,7 +225,7 @@ The loop [`else` clause][loop else] is unique to Python and can be used for "wra ... # This statement does not run, because a *break* was triggered. ... else: -... print(f"Found the above b-words, out of {len(word_list)} words in the word list.") +... print(f"Found the above b-words, out of {len(word_list)} words in the word list.") ... 'Bird (at index 0) starts with a B.' 'Barrel (at index 2) starts with a B.' diff --git a/exercises/concept/making-the-grade/.docs/hints.md b/exercises/concept/making-the-grade/.docs/hints.md index 3e8deff9581..eee64b21ac7 100644 --- a/exercises/concept/making-the-grade/.docs/hints.md +++ b/exercises/concept/making-the-grade/.docs/hints.md @@ -2,15 +2,15 @@ ## General -- [`while`][while-loops] loops are used for _indefinite_ (uncounted) iteration -- [`for`][for-loops] loops are used for _definite_, (counted) iteration. +- [`while`][while-loops] loops are used for _indefinite_ (uncounted) iteration. +- [`for`][for-loops] loops are used for _definite_ (counted) iteration. - The keywords [`break` and `continue`][control flow] help customize loop behavior. -- [`range(, stop, )`][range] can be used to generate a sequence for a loop counter. +- [`range(, , )`][range] can be used to generate a sequence for a loop counter. - The built-in [`enumerate()`][enumerate] will return (``, ``) pairs to iterate over. Also being familiar with the following can help with completing the tasks: -- [`lists`][list]: indexing, nested lists, [`.append`][append and pop], [`.pop()`][append and pop]. +- [`lists`][list]: indexing, nested lists, [`.append()`][append and pop], [`.pop()`][append and pop]. - [`str`][str]: `str()` constructor, using the `+` to concatenate strings, optionally, [`f-strings`][f-strings]. ## 1. Rounding Scores @@ -22,7 +22,7 @@ Also being familiar with the following can help with completing the tasks: ## 2. Non-Passing Students - There's no need to declare `loop` counters or `index` counters when iterating through an object using a `for` loop. -- A results counter does need to be set up and _incremented_ -- you'll want to `return` the count of non-passing students when the loop terminates. +- A results counter does need to be set up and _incremented_ — you'll want to `return` the count of non-passing students when the loop terminates. ## 3. The "Best" diff --git a/exercises/concept/making-the-grade/.meta/exemplar.py b/exercises/concept/making-the-grade/.meta/exemplar.py index c490dbf1c64..2a8f52846b0 100644 --- a/exercises/concept/making-the-grade/.meta/exemplar.py +++ b/exercises/concept/making-the-grade/.meta/exemplar.py @@ -5,7 +5,7 @@ def round_scores(student_scores): """Round all provided student scores. Parameters: - student_scores (list[float|int]): Student exam scores. + student_scores (list[float]): Student exam scores. Returns: list[int]: Student scores *rounded* to the nearest integer value. @@ -42,7 +42,7 @@ def above_threshold(student_scores, threshold): threshold (int): The threshold to cross to be the "best" score. Returns: - list[int]: Integer scores that are at or above the "best" threshold. + list[int]: Integer scores that are at or above the "best" threshold. """ above = [] @@ -57,7 +57,7 @@ def letter_grades(highest): """Create a list of grade thresholds based on the provided highest grade. Parameters: - highest: int - value of the highest exam score. + highest (int): The value of the highest exam score. Returns: list[int]: Lower threshold scores for each D-A letter grade interval. @@ -85,7 +85,7 @@ def student_ranking(student_scores, student_names): student_names (list[str]): Student names by exam score in descending order. Returns: - list[str]: Strings in format [". : "]. + list[str]: Strings in format [". : "]. """ results = [] diff --git a/exercises/concept/making-the-grade/loops.py b/exercises/concept/making-the-grade/loops.py index 21da8c77e8a..5bc0c72722f 100644 --- a/exercises/concept/making-the-grade/loops.py +++ b/exercises/concept/making-the-grade/loops.py @@ -5,7 +5,7 @@ def round_scores(student_scores): """Round all provided student scores. Parameters: - student_scores (list[float|int]): Student exam scores. + student_scores (list[float]): Student exam scores. Returns: list[int]: Student scores *rounded* to the nearest integer value. @@ -35,7 +35,7 @@ def above_threshold(student_scores, threshold): threshold (int): The threshold to cross to be the "best" score. Returns: - list[int]: Integer scores that are at or above the "best" threshold. + list[int]: Integer scores that are at or above the "best" threshold. """ pass @@ -45,7 +45,7 @@ def letter_grades(highest): """Create a list of grade thresholds based on the provided highest grade. Parameters: - highest: int - value of the highest exam score. + highest (int): The value of the highest exam score. Returns: list[int]: Lower threshold scores for each D-A letter grade interval. @@ -69,7 +69,7 @@ def student_ranking(student_scores, student_names): student_names (list[str]): Student names by exam score in descending order. Returns: - list[str]: Strings in format [". : "]. + list[str]: Strings in format [". : "]. """ pass