generated from mwc/lab_iteration
I deleted the pass and wrote the range code based on the instructions.
One thing I found interesting about ranges is that I can control where to start and stop and how many stride it can take. I also found it interesting that if you write a range(0,5), it doesn't stop at 5 but before 5. For now, Im not unsure about anything related to range.
This commit is contained in:
11
ranges.py
11
ranges.py
@@ -4,20 +4,23 @@
|
|||||||
|
|
||||||
def print_all_numbers(maximum):
|
def print_all_numbers(maximum):
|
||||||
"Prints all integers from 0 to maximum."
|
"Prints all integers from 0 to maximum."
|
||||||
for number in range(maximum):
|
for number in range(20):
|
||||||
print(number)
|
print(number)
|
||||||
|
|
||||||
def print_even_numbers(maximum):
|
def print_even_numbers(maximum):
|
||||||
"Prints all even integers from 0 to maximum."
|
"Prints all even integers from 0 to maximum."
|
||||||
pass
|
for number in range(0,20,2):
|
||||||
|
print(number)
|
||||||
|
|
||||||
def print_odd_numbers(maximum):
|
def print_odd_numbers(maximum):
|
||||||
"Prints all odd integers from 0 to 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):
|
def print_multiples_of_five(maximum):
|
||||||
"Prints all integers which are multiples of five from 0 to maximum."
|
"Prints all integers which are multiples of five from 0 to maximum."
|
||||||
pass
|
for number in range(5,30,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(f"All numbers from 0 to {chosen_maximum}")
|
||||||
|
|||||||
Reference in New Issue
Block a user