generated from mwc/lab_iteration
Print numbers from 1-20, odds, even and in multiples of 5
something interesting about ranges is that it alway skips the last numbers something im still unsure about is why in line 26 "Choose a number:" need a :
This commit is contained in:
15
ranges.py
15
ranges.py
@@ -9,17 +9,21 @@ def print_all_numbers(maximum):
|
||||
|
||||
def print_even_numbers(maximum):
|
||||
"Prints all even integers from 0 to maximum."
|
||||
pass
|
||||
for number in range(0, 21, 2):
|
||||
print(number)
|
||||
|
||||
def print_odd_numbers(maximum):
|
||||
"Prints all odd integers from 0 to maximum."
|
||||
pass
|
||||
for number in range(1, 20, 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, 21, 5):
|
||||
print(number)
|
||||
|
||||
chosen_maximum = int(input("Choose a number: "))
|
||||
|
||||
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}")
|
||||
@@ -27,5 +31,4 @@ 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)
|
||||
|
||||
print_multiples_of_five(chosen_maximum)
|
||||
Reference in New Issue
Block a user