From 69d2c6c960803e6af30bfa0a89dd284825837023 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Tue, 4 Feb 2025 10:28:12 -0500 Subject: [PATCH 01/22] Add files via upload --- python-break/for_loop_test_scores_example.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 python-break/for_loop_test_scores_example.py diff --git a/python-break/for_loop_test_scores_example.py b/python-break/for_loop_test_scores_example.py new file mode 100644 index 0000000000..c22a447b56 --- /dev/null +++ b/python-break/for_loop_test_scores_example.py @@ -0,0 +1,14 @@ +# Use case 1: If the student fails 2 or more tests, the student must go to tutoring (for loop) +scores = [90, 30, 50, 70, 85, 35] + +numFailedScores = 0 +failedScore = 60 +needsTutoring = False +for score in scores: + if score < failedScore: + numFailedScores += 1 + if numFailedScores >= 2: + needsTutoring = True + break + +print("Does the student need tutoring? " + str(needsTutoring)) From 30b6d8cea59352ae1ec3cb4cf7cdc47aabec6069 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Tue, 4 Feb 2025 11:16:49 -0500 Subject: [PATCH 02/22] Updated for-loop code example Changed variable names to use underscores, rather than camel-case --- python-break/for_loop_test_scores_example.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python-break/for_loop_test_scores_example.py b/python-break/for_loop_test_scores_example.py index c22a447b56..4d4778e700 100644 --- a/python-break/for_loop_test_scores_example.py +++ b/python-break/for_loop_test_scores_example.py @@ -1,14 +1,14 @@ -# Use case 1: If the student fails 2 or more tests, the student must go to tutoring (for loop) +# Use case 1: If the student fails 2 or more tests, the student must go to tutoring (for-loop) scores = [90, 30, 50, 70, 85, 35] -numFailedScores = 0 -failedScore = 60 -needsTutoring = False +num_failed_scores = 0 +failed_score = 60 +needs_utoring = False for score in scores: - if score < failedScore: - numFailedScores += 1 - if numFailedScores >= 2: - needsTutoring = True + if score < failed_score: + num_failed_scores += 1 + if num_failed_scores >= 2: + needs_tutoring = True break -print("Does the student need tutoring? " + str(needsTutoring)) +print("Does the student need tutoring? " + str(needs_tutoring)) From 763c7265e1b6dbff497d01034da4bdc85d0a6bbb Mon Sep 17 00:00:00 2001 From: dphoenix Date: Tue, 4 Feb 2025 11:33:31 -0500 Subject: [PATCH 03/22] While loop example Breaking out of a while loop early. Code example prints out first five (or less) test scores. --- python-break/while_loop_print_test_scores_example.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 python-break/while_loop_print_test_scores_example.py diff --git a/python-break/while_loop_print_test_scores_example.py b/python-break/while_loop_print_test_scores_example.py new file mode 100644 index 0000000000..b46711e79e --- /dev/null +++ b/python-break/while_loop_print_test_scores_example.py @@ -0,0 +1,10 @@ +# Use case 2: Print out the score of the first five tests (while loop) +scores = [90, 30, 50] +i = 0 + +while i < 5: + if i > len(scores) - 1: + # If there are less than 5 scores, break out of the loop when all scores are printed + break + print("Score: " + str(scores[i])) + i += 1 From 38a59b744460a4a57bd72fc3576d4a065b8ba866 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Tue, 4 Feb 2025 11:58:42 -0500 Subject: [PATCH 04/22] Uploaded new example Code example for getting user input --- python-break/user_input_example.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 python-break/user_input_example.py diff --git a/python-break/user_input_example.py b/python-break/user_input_example.py new file mode 100644 index 0000000000..54aa2e2bc5 --- /dev/null +++ b/python-break/user_input_example.py @@ -0,0 +1,26 @@ +# Use case 3: Getting user input + +# Import the random module for generating random numbers +import random + +guesses_left = 4 +random_number = random.randint(1, 10) + +while True: + if guesses_left <= 0: + print("You ran out of guesses! The correct number was " + str(random_number)) + break + guess = input("Guess a number between 1 and 10, or enter q to quit:") + if guess == "q": + print("Successfully exited game.") + break + elif(not(guess.isnumeric())): + guess = input("Please enter a valid value: ") + else: + if int(guess) == random_number: + print("Congratulations, you picked the correct number!") + break + else: + print("Sorry, your guess was incorrect.") + guesses_left -= 1 + print("You have " + str(guesses_left) + " guesses left.") From f4d14af6cda6b19fd8ad60df9e4ffc38ea63c4ab Mon Sep 17 00:00:00 2001 From: dphoenix Date: Tue, 4 Feb 2025 12:12:28 -0500 Subject: [PATCH 05/22] Add files via upload Nested loop example, which prints out the number of students who got at least one failed score --- ...sted_loop_number_of_failed_students_example.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 python-break/nested_loop_number_of_failed_students_example.py diff --git a/python-break/nested_loop_number_of_failed_students_example.py b/python-break/nested_loop_number_of_failed_students_example.py new file mode 100644 index 0000000000..ef2410611c --- /dev/null +++ b/python-break/nested_loop_number_of_failed_students_example.py @@ -0,0 +1,15 @@ +# Use case 4: Check to see how many students have failed a test (nested loop) +scores = [ + [90, 30, 80, 100], + [100, 80, 95, 87], + [75, 84, 77, 90] +] + +failed_score = 60 +num_failed_students = 0 +for score_set in scores: + for score in score_set: + if score < failed_score: + num_failed_students += 1 + break +print("Number of students who failed a test: " + str(num_failed_students)) From 4fa269a509a4281328117bcc2e415f760d4445c6 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 5 Feb 2025 21:27:26 +0100 Subject: [PATCH 06/22] Make linter happy --- python-break/for_loop_test_scores_example.py | 3 ++- .../nested_loop_number_of_failed_students_example.py | 6 +----- python-break/user_input_example.py | 7 +++++-- python-break/while_loop_print_test_scores_example.py | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/python-break/for_loop_test_scores_example.py b/python-break/for_loop_test_scores_example.py index 4d4778e700..1f11c3278b 100644 --- a/python-break/for_loop_test_scores_example.py +++ b/python-break/for_loop_test_scores_example.py @@ -1,4 +1,5 @@ -# Use case 1: If the student fails 2 or more tests, the student must go to tutoring (for-loop) +# Use case 1: If the student fails 2 or more tests, +# the student must go to tutoring (for-loop) scores = [90, 30, 50, 70, 85, 35] num_failed_scores = 0 diff --git a/python-break/nested_loop_number_of_failed_students_example.py b/python-break/nested_loop_number_of_failed_students_example.py index ef2410611c..cb641c78a0 100644 --- a/python-break/nested_loop_number_of_failed_students_example.py +++ b/python-break/nested_loop_number_of_failed_students_example.py @@ -1,9 +1,5 @@ # Use case 4: Check to see how many students have failed a test (nested loop) -scores = [ - [90, 30, 80, 100], - [100, 80, 95, 87], - [75, 84, 77, 90] -] +scores = [[90, 30, 80, 100], [100, 80, 95, 87], [75, 84, 77, 90]] failed_score = 60 num_failed_students = 0 diff --git a/python-break/user_input_example.py b/python-break/user_input_example.py index 54aa2e2bc5..9deb2f80e7 100644 --- a/python-break/user_input_example.py +++ b/python-break/user_input_example.py @@ -8,13 +8,16 @@ while True: if guesses_left <= 0: - print("You ran out of guesses! The correct number was " + str(random_number)) + print( + "You ran out of guesses! The correct number was " + + str(random_number) + ) break guess = input("Guess a number between 1 and 10, or enter q to quit:") if guess == "q": print("Successfully exited game.") break - elif(not(guess.isnumeric())): + elif not (guess.isnumeric()): guess = input("Please enter a valid value: ") else: if int(guess) == random_number: diff --git a/python-break/while_loop_print_test_scores_example.py b/python-break/while_loop_print_test_scores_example.py index b46711e79e..e5d6b6b1cf 100644 --- a/python-break/while_loop_print_test_scores_example.py +++ b/python-break/while_loop_print_test_scores_example.py @@ -4,7 +4,8 @@ while i < 5: if i > len(scores) - 1: - # If there are less than 5 scores, break out of the loop when all scores are printed + # If there are less than 5 scores, + # break out of the loop when all scores are printed break print("Score: " + str(scores[i])) i += 1 From e592cfc9e86788554a8d0cb1510efc0a835b25b6 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 5 Feb 2025 21:32:19 +0100 Subject: [PATCH 07/22] Add README file --- python-break/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 python-break/README.md diff --git a/python-break/README.md b/python-break/README.md new file mode 100644 index 0000000000..87d650e122 --- /dev/null +++ b/python-break/README.md @@ -0,0 +1,3 @@ +# Python break: Exit Loops Early With Python's Break Keyword + +This folder provides the code examples for the Real Python tutorial [Python break: Exit Loops Early With Python's Break Keyword](https://realpython.com/python-break/). From b393891c240ad92f093723f128df4916cac9d97f Mon Sep 17 00:00:00 2001 From: dphoenix Date: Thu, 6 Feb 2025 11:27:07 -0500 Subject: [PATCH 08/22] Update for_loop_test_scores_example.py Fixed a variable typo --- python-break/for_loop_test_scores_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-break/for_loop_test_scores_example.py b/python-break/for_loop_test_scores_example.py index 1f11c3278b..18e46259b5 100644 --- a/python-break/for_loop_test_scores_example.py +++ b/python-break/for_loop_test_scores_example.py @@ -4,7 +4,7 @@ num_failed_scores = 0 failed_score = 60 -needs_utoring = False +needs_tutoring = False for score in scores: if score < failed_score: num_failed_scores += 1 From 1c08fe0aa2faceb50d47db7a060d78c5dd1a3def Mon Sep 17 00:00:00 2001 From: dphoenix Date: Thu, 6 Feb 2025 11:48:03 -0500 Subject: [PATCH 09/22] Update for_loop_test_scores_example.py - Changed True/False values to "Yes"/"No", to make output more reader-friendly - Used f-string for string interpolation --- python-break/for_loop_test_scores_example.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python-break/for_loop_test_scores_example.py b/python-break/for_loop_test_scores_example.py index 18e46259b5..bdfc3025c5 100644 --- a/python-break/for_loop_test_scores_example.py +++ b/python-break/for_loop_test_scores_example.py @@ -4,12 +4,12 @@ num_failed_scores = 0 failed_score = 60 -needs_tutoring = False +needs_tutoring = "No" for score in scores: if score < failed_score: num_failed_scores += 1 if num_failed_scores >= 2: - needs_tutoring = True + needs_tutoring = "Yes" break -print("Does the student need tutoring? " + str(needs_tutoring)) +print(f"Does the student need tutoring? {needs_tutoring}") From de366394b6976a23214f3afbf61191b203df55f8 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Fri, 7 Feb 2025 13:47:35 -0500 Subject: [PATCH 10/22] Update nested_loop_number_of_failed_students_example.py From 415c5cba06fa8aa451b026480ff671bf442ccc2e Mon Sep 17 00:00:00 2001 From: dphoenix Date: Fri, 7 Feb 2025 13:49:12 -0500 Subject: [PATCH 11/22] Update user_input_example.py Used f-strings for string interpolation --- python-break/user_input_example.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python-break/user_input_example.py b/python-break/user_input_example.py index 9deb2f80e7..a76ed2904a 100644 --- a/python-break/user_input_example.py +++ b/python-break/user_input_example.py @@ -9,8 +9,7 @@ while True: if guesses_left <= 0: print( - "You ran out of guesses! The correct number was " - + str(random_number) + f"You ran out of guesses! The correct number was {random_number}" ) break guess = input("Guess a number between 1 and 10, or enter q to quit:") @@ -26,4 +25,4 @@ else: print("Sorry, your guess was incorrect.") guesses_left -= 1 - print("You have " + str(guesses_left) + " guesses left.") + print(f"You have {guesses_left} guesses left.") From d5ad22932e2574bb41fe58404b8cb8a892a4bbc2 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Fri, 7 Feb 2025 14:02:27 -0500 Subject: [PATCH 12/22] Update user_input_example.py Removed unnecessary nested loop --- python-break/user_input_example.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/python-break/user_input_example.py b/python-break/user_input_example.py index a76ed2904a..cdd5c53c80 100644 --- a/python-break/user_input_example.py +++ b/python-break/user_input_example.py @@ -8,21 +8,18 @@ while True: if guesses_left <= 0: - print( - f"You ran out of guesses! The correct number was {random_number}" - ) + print(f"You ran out of guesses! The correct number was {random_number}") break guess = input("Guess a number between 1 and 10, or enter q to quit:") if guess == "q": print("Successfully exited game.") break - elif not (guess.isnumeric()): - guess = input("Please enter a valid value: ") + elif(not(guess.isnumeric())): + print("Please enter a valid value.") + elif int(guess) == random_number: + print("Congratulations, you picked the correct number!") + break else: - if int(guess) == random_number: - print("Congratulations, you picked the correct number!") - break - else: - print("Sorry, your guess was incorrect.") - guesses_left -= 1 - print(f"You have {guesses_left} guesses left.") + print("Sorry, your guess was incorrect.") + guesses_left -= 1 + print(f"You have {guesses_left} guesses left.") From f62583d5d2e2f3e06dcf4fb60b70fbb6a27920fc Mon Sep 17 00:00:00 2001 From: dphoenix Date: Sat, 8 Feb 2025 15:54:12 -0500 Subject: [PATCH 13/22] Update nested_loop_number_of_failed_students_example.py Created a more meaningful variable name --- python-break/nested_loop_number_of_failed_students_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-break/nested_loop_number_of_failed_students_example.py b/python-break/nested_loop_number_of_failed_students_example.py index cb641c78a0..06e737016c 100644 --- a/python-break/nested_loop_number_of_failed_students_example.py +++ b/python-break/nested_loop_number_of_failed_students_example.py @@ -3,8 +3,8 @@ failed_score = 60 num_failed_students = 0 -for score_set in scores: - for score in score_set: +for student_score_list in scores: + for score in student_score_list: if score < failed_score: num_failed_students += 1 break From 63c4945f7fbe9731876ac0e5c3debfb8478d9989 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 13 Feb 2025 16:38:15 +0100 Subject: [PATCH 14/22] Use black formatting --- python-break/user_input_example.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python-break/user_input_example.py b/python-break/user_input_example.py index cdd5c53c80..22d9427a7d 100644 --- a/python-break/user_input_example.py +++ b/python-break/user_input_example.py @@ -8,13 +8,15 @@ while True: if guesses_left <= 0: - print(f"You ran out of guesses! The correct number was {random_number}") + print( + f"You ran out of guesses! The correct number was {random_number}" + ) break guess = input("Guess a number between 1 and 10, or enter q to quit:") if guess == "q": print("Successfully exited game.") break - elif(not(guess.isnumeric())): + elif not (guess.isnumeric()): print("Please enter a valid value.") elif int(guess) == random_number: print("Congratulations, you picked the correct number!") From b41931b3b30a4ffcfeef1957ac638b9488087bd4 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Mon, 17 Mar 2025 02:37:49 -0400 Subject: [PATCH 15/22] Create break_statement_introduction.py --- python-break/break_statement_introduction.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 python-break/break_statement_introduction.py diff --git a/python-break/break_statement_introduction.py b/python-break/break_statement_introduction.py new file mode 100644 index 0000000000..2f36162654 --- /dev/null +++ b/python-break/break_statement_introduction.py @@ -0,0 +1,4 @@ +for number in range(10): + if number > 5: + break + print(number) From 6d9e6fc1a07b8fc704003cc3719e9059899b2eb6 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Mon, 17 Mar 2025 02:53:51 -0400 Subject: [PATCH 16/22] Changed directory name to match article slug, and updated code samples --- .../README.md | 0 .../break_statement_introduction.py | 0 .../continue_statement_example.py | 4 ++++ .../for_loop_test_scores_example.py | 9 +++++++++ .../for_loop_test_scores_example_with_tutor_rec.py | 2 -- .../nested_loop_number_of_failed_students_example.py | 1 - .../user_input_example.py | 3 --- python-break/while_loop_print_test_scores_example.py | 11 ----------- 8 files changed, 13 insertions(+), 17 deletions(-) rename {python-break => how-to-exit-loops-early-with-python-break-keyword}/README.md (100%) rename {python-break => how-to-exit-loops-early-with-python-break-keyword}/break_statement_introduction.py (100%) create mode 100644 how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py create mode 100644 how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py rename python-break/for_loop_test_scores_example.py => how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example_with_tutor_rec.py (73%) rename {python-break => how-to-exit-loops-early-with-python-break-keyword}/nested_loop_number_of_failed_students_example.py (79%) rename {python-break => how-to-exit-loops-early-with-python-break-keyword}/user_input_example.py (85%) delete mode 100644 python-break/while_loop_print_test_scores_example.py diff --git a/python-break/README.md b/how-to-exit-loops-early-with-python-break-keyword/README.md similarity index 100% rename from python-break/README.md rename to how-to-exit-loops-early-with-python-break-keyword/README.md diff --git a/python-break/break_statement_introduction.py b/how-to-exit-loops-early-with-python-break-keyword/break_statement_introduction.py similarity index 100% rename from python-break/break_statement_introduction.py rename to how-to-exit-loops-early-with-python-break-keyword/break_statement_introduction.py diff --git a/how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py b/how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py new file mode 100644 index 0000000000..6428ae1f19 --- /dev/null +++ b/how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py @@ -0,0 +1,4 @@ +for index in range(6): + if index % 2 == 0: + continue + print(index) \ No newline at end of file diff --git a/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py b/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py new file mode 100644 index 0000000000..658c70672c --- /dev/null +++ b/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py @@ -0,0 +1,9 @@ +scores = [90, 30, 50, 70, 85, 35] + +num_failed_scores = 0 +failed_score = 60 +for score in scores: + if score < failed_score: + num_failed_scores += 1 + +print(f"Number of failed tests: {num_failed_scores}") \ No newline at end of file diff --git a/python-break/for_loop_test_scores_example.py b/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example_with_tutor_rec.py similarity index 73% rename from python-break/for_loop_test_scores_example.py rename to how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example_with_tutor_rec.py index bdfc3025c5..a06273c343 100644 --- a/python-break/for_loop_test_scores_example.py +++ b/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example_with_tutor_rec.py @@ -1,5 +1,3 @@ -# Use case 1: If the student fails 2 or more tests, -# the student must go to tutoring (for-loop) scores = [90, 30, 50, 70, 85, 35] num_failed_scores = 0 diff --git a/python-break/nested_loop_number_of_failed_students_example.py b/how-to-exit-loops-early-with-python-break-keyword/nested_loop_number_of_failed_students_example.py similarity index 79% rename from python-break/nested_loop_number_of_failed_students_example.py rename to how-to-exit-loops-early-with-python-break-keyword/nested_loop_number_of_failed_students_example.py index 06e737016c..a02ea2d02d 100644 --- a/python-break/nested_loop_number_of_failed_students_example.py +++ b/how-to-exit-loops-early-with-python-break-keyword/nested_loop_number_of_failed_students_example.py @@ -1,4 +1,3 @@ -# Use case 4: Check to see how many students have failed a test (nested loop) scores = [[90, 30, 80, 100], [100, 80, 95, 87], [75, 84, 77, 90]] failed_score = 60 diff --git a/python-break/user_input_example.py b/how-to-exit-loops-early-with-python-break-keyword/user_input_example.py similarity index 85% rename from python-break/user_input_example.py rename to how-to-exit-loops-early-with-python-break-keyword/user_input_example.py index 22d9427a7d..f4f9c18d59 100644 --- a/python-break/user_input_example.py +++ b/how-to-exit-loops-early-with-python-break-keyword/user_input_example.py @@ -1,6 +1,3 @@ -# Use case 3: Getting user input - -# Import the random module for generating random numbers import random guesses_left = 4 diff --git a/python-break/while_loop_print_test_scores_example.py b/python-break/while_loop_print_test_scores_example.py deleted file mode 100644 index e5d6b6b1cf..0000000000 --- a/python-break/while_loop_print_test_scores_example.py +++ /dev/null @@ -1,11 +0,0 @@ -# Use case 2: Print out the score of the first five tests (while loop) -scores = [90, 30, 50] -i = 0 - -while i < 5: - if i > len(scores) - 1: - # If there are less than 5 scores, - # break out of the loop when all scores are printed - break - print("Score: " + str(scores[i])) - i += 1 From 01b96ec78dd68f6b4f184bbde4ac7eb60e83644c Mon Sep 17 00:00:00 2001 From: dphoenix Date: Mon, 17 Mar 2025 03:22:12 -0400 Subject: [PATCH 17/22] Update break_statement_introduction.py --- .../break_statement_introduction.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/how-to-exit-loops-early-with-python-break-keyword/break_statement_introduction.py b/how-to-exit-loops-early-with-python-break-keyword/break_statement_introduction.py index 2f36162654..ed394379e6 100644 --- a/how-to-exit-loops-early-with-python-break-keyword/break_statement_introduction.py +++ b/how-to-exit-loops-early-with-python-break-keyword/break_statement_introduction.py @@ -1,4 +1,4 @@ for number in range(10): - if number > 5: - break - print(number) + if number > 5: + break + print(number) From 4369b21ecdf403834e1f1169bc95dad23af4a6ae Mon Sep 17 00:00:00 2001 From: dphoenix Date: Mon, 17 Mar 2025 03:23:20 -0400 Subject: [PATCH 18/22] Update continue_statement_example.py --- .../continue_statement_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py b/how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py index 6428ae1f19..b437ca25fd 100644 --- a/how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py +++ b/how-to-exit-loops-early-with-python-break-keyword/continue_statement_example.py @@ -1,4 +1,4 @@ for index in range(6): if index % 2 == 0: continue - print(index) \ No newline at end of file + print(index) From 8d58950c63aebeaae6582fe7a877d6951186d4e7 Mon Sep 17 00:00:00 2001 From: dphoenix Date: Mon, 17 Mar 2025 03:25:09 -0400 Subject: [PATCH 19/22] Update for_loop_test_scores_example.py --- .../for_loop_test_scores_example.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py b/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py index 658c70672c..d8bb5943f8 100644 --- a/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py +++ b/how-to-exit-loops-early-with-python-break-keyword/for_loop_test_scores_example.py @@ -5,5 +5,4 @@ for score in scores: if score < failed_score: num_failed_scores += 1 - -print(f"Number of failed tests: {num_failed_scores}") \ No newline at end of file +print(f"Number of failed tests: {num_failed_scores}") From 8ad233552f6921dd31a2871c9ef340cfb6908eda Mon Sep 17 00:00:00 2001 From: brendaweles <160772586+brendaweles@users.noreply.github.com> Date: Wed, 2 Apr 2025 16:43:20 -0600 Subject: [PATCH 20/22] Update README.md --- how-to-exit-loops-early-with-python-break-keyword/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/how-to-exit-loops-early-with-python-break-keyword/README.md b/how-to-exit-loops-early-with-python-break-keyword/README.md index 87d650e122..e41f38d8f4 100644 --- a/how-to-exit-loops-early-with-python-break-keyword/README.md +++ b/how-to-exit-loops-early-with-python-break-keyword/README.md @@ -1,3 +1,3 @@ -# Python break: Exit Loops Early With Python's Break Keyword +# How to Exit Loops Early With the Python Break Keyword -This folder provides the code examples for the Real Python tutorial [Python break: Exit Loops Early With Python's Break Keyword](https://realpython.com/python-break/). +This folder provides the code examples for the Real Python tutorial [How to Exit Loops Early With the Python Break Keyword](https://realpython.com/python-break/). From e25248d0833c28e26687633713e4d14a3a027244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Zaczy=C5=84ski?= Date: Thu, 3 Apr 2025 10:16:55 +0200 Subject: [PATCH 21/22] Update user_input_example.py --- .../user_input_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/how-to-exit-loops-early-with-python-break-keyword/user_input_example.py b/how-to-exit-loops-early-with-python-break-keyword/user_input_example.py index f4f9c18d59..c26b90402d 100644 --- a/how-to-exit-loops-early-with-python-break-keyword/user_input_example.py +++ b/how-to-exit-loops-early-with-python-break-keyword/user_input_example.py @@ -9,7 +9,7 @@ f"You ran out of guesses! The correct number was {random_number}" ) break - guess = input("Guess a number between 1 and 10, or enter q to quit:") + guess = input("Guess a number between 1 and 10, or enter q to quit: ") if guess == "q": print("Successfully exited game.") break From 893f429ef27f9ec09bd8f3310f01100efb144e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Zaczy=C5=84ski?= Date: Thu, 3 Apr 2025 10:17:35 +0200 Subject: [PATCH 22/22] Update nested_loop_number_of_failed_students_example.py --- .../nested_loop_number_of_failed_students_example.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/how-to-exit-loops-early-with-python-break-keyword/nested_loop_number_of_failed_students_example.py b/how-to-exit-loops-early-with-python-break-keyword/nested_loop_number_of_failed_students_example.py index a02ea2d02d..509c6127a5 100644 --- a/how-to-exit-loops-early-with-python-break-keyword/nested_loop_number_of_failed_students_example.py +++ b/how-to-exit-loops-early-with-python-break-keyword/nested_loop_number_of_failed_students_example.py @@ -1,4 +1,4 @@ -scores = [[90, 30, 80, 100], [100, 80, 95, 87], [75, 84, 77, 90]] +scores = [[90, 30, 80, 100], [100, 80, 95, 87], [75, 84, 77, 50]] failed_score = 60 num_failed_students = 0 @@ -7,4 +7,5 @@ if score < failed_score: num_failed_students += 1 break -print("Number of students who failed a test: " + str(num_failed_students)) + +print(f"Number of students who failed a test: {num_failed_students}")