generated from mwc/lab_iteration
I implemented print_even_numbers,
print_odd_numbers, and print_multiples_of_five. Checkpoint 2: I understand the "stride" in a for loop. Overall, I feel comfortable with ranges. The only thing I was unsure of was whether I did print_even_numbers correctly. The assignment specified that print_all_numbers was implemented correctly, and when I input 8 the output was the integers from 0 to 7 inclusive. When I did print_even_numbers(8), it returned 0 2 4 6. I would've thought from the description, returning even numbers from 0 to maximum, would also include 8, but since print_all_numbers did not include the maximum itself, I left it as is.
This commit is contained in:
parent
daae31288d
commit
34ca650305
11
ranges.py
11
ranges.py
|
@ -9,15 +9,16 @@ 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 (1,maximum,2):
|
||||
print(number)
|
||||
|
||||
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}")
|
||||
|
|
Loading…
Reference in New Issue