generated from mwc/lab_iteration
	ranges.py
I feel at home on the range! Let's say I coded: x in range(0, 100, -5), what kind of error message, if any, would this generate?
This commit is contained in:
		
							
								
								
									
										18
									
								
								ranges.py
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								ranges.py
									
									
									
									
									
								
							@@ -1,6 +1,7 @@
 | 
			
		||||
# ranges.py
 | 
			
		||||
# ---------
 | 
			
		||||
# By MWC Contributors
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
def print_all_numbers(maximum):
 | 
			
		||||
    "Prints all integers from 0 to maximum."
 | 
			
		||||
@@ -9,23 +10,34 @@ 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)
 | 
			
		||||
 | 
			
		||||
def clear_screen():
 | 
			
		||||
    os.system('clear')
 | 
			
		||||
 | 
			
		||||
clear_screen()
 | 
			
		||||
chosen_maximum = int(input("Choose a number: "))
 | 
			
		||||
print(f"All numbers from 0 to {chosen_maximum}")
 | 
			
		||||
print_all_numbers(chosen_maximum)
 | 
			
		||||
input("Press ENTER to continue")
 | 
			
		||||
print(f"All even numbers from 0 to {chosen_maximum}")
 | 
			
		||||
print_even_numbers(chosen_maximum)
 | 
			
		||||
input("Press ENTER to continue")
 | 
			
		||||
print(f"All odd numbers from 0 to {chosen_maximum}")
 | 
			
		||||
print_odd_numbers(chosen_maximum)
 | 
			
		||||
input("Press ENTER to continue")
 | 
			
		||||
print(f"All multiples of 5 from  0 to {chosen_maximum}")
 | 
			
		||||
print_multiples_of_five(chosen_maximum)
 | 
			
		||||
input("Press ENTER to continue")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user