From 84a669040999d7ace409f42641760edf20c9f6d2 Mon Sep 17 00:00:00 2001 From: kdang Date: Wed, 24 Sep 2025 09:19:22 -0400 Subject: [PATCH] I made the print_even_numbers, print_odd_numbers and print_multiples_of_five code work. It was difficulty to figure out how to rewrite square() with a for-loop, I had to try out many different ways to use the for-loop code before it finally worked. Something interesting I find about ranges is how it does not count the maximum when printing the numbers. Why does it not count the maximum? --- ranges.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ranges.py b/ranges.py index 2fa00d7..aeaab29 100644 --- a/ranges.py +++ b/ranges.py @@ -9,15 +9,18 @@ def print_all_numbers(maximum): def print_even_numbers(maximum): "Prints all even integers from 0 to maximum." - pass + for number in range(0, maximum, 2): + print(number) def print_odd_numbers(maximum): "Prints all odd integers from 0 to maximum." - pass + for number in range(0, maximum, 2): + print(number + 1) def print_multiples_of_five(maximum): "Prints all integers which are multiples of five from 0 to maximum." - pass + for number in range(0, maximum, 5): + print(number) chosen_maximum = int(input("Choose a number: ")) print(f"All numbers from 0 to {chosen_maximum}")