Files
lab_iteration/ranges.py
cramsey e36cc4cc78 It was difficult to figure out how to write the
for-loop. I mostly figured it out with help. (checkpoint 1)
I understand how to make the ranges well although it did take
a bit to understand completely how to write them. (checkpoint 2)
2025-09-30 09:43:14 -04:00

35 lines
1.0 KiB
Python

# ranges.py
# ---------
# By MWC Contributors
def print_all_numbers(maximum):
"Prints all integers from 0 to maximum."
for numbers in range(maximum):
print(numbers)
def print_even_numbers(maximum):
"Prints all even integers from 0 to maximum."
for numbers in range(0,maximum,2):
print(numbers)
def print_odd_numbers(maximum):
"Prints all odd integers from 0 to maximum."
for numbers in range(1,maximum,2):
print(numbers)
def print_multiples_of_five(maximum):
"Prints all integers which are multiples of five from 0 to maximum."
for numbers in range(0,maximum,5):
print(numbers)
chosen_maximum = int(input("Choose a number: "))
print(f"All numbers from 0 to {chosen_maximum}")
print_all_numbers(chosen_maximum)
print(f"All even numbers from 0 to {chosen_maximum}")
print_even_numbers(chosen_maximum)
print(f"All odd numbers from 0 to {chosen_maximum}")
print_odd_numbers(chosen_maximum)
print(f"All multiples of 5 from 0 to {chosen_maximum}")
print_multiples_of_five(chosen_maximum)