generated from mwc/lab_iteration
checkpoint 1: no it wasn't difficult, i know how to use for loops checkpoint 2: ranges are super helpful in iteration and can be very useful when you want to repeat stuff or go through data checkpoint 3: yes, i do think i will write docstrings. I've read them in the past and have found them very insightful. they make it easier to know how programs work, similar to comments in functions.
35 lines
1018 B
Python
35 lines
1018 B
Python
# ranges.py
|
|
# ---------
|
|
# By MWC Contributors
|
|
|
|
def print_all_numbers(maximum):
|
|
"Prints all integers from 0 to maximum."
|
|
for number in range(maximum):
|
|
print(number)
|
|
|
|
def print_even_numbers(maximum):
|
|
"Prints all even integers from 0 to maximum."
|
|
for x in range(0,maximum,2):
|
|
print (x)
|
|
|
|
def print_odd_numbers(maximum):
|
|
"Prints all odd integers from 0 to maximum."
|
|
for x in range(1,maximum,2):
|
|
print (x)
|
|
|
|
def print_multiples_of_five(maximum):
|
|
"Prints all integers which are multiples of five from 0 to maximum."
|
|
for x in range(0,maximum,5):
|
|
print (x)
|
|
|
|
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)
|
|
|