Created
December 20, 2020 07:09
-
-
Save ayubmetah/f1067363a2cb92ee5d594ba3ac09cc5e to your computer and use it in GitHub Desktop.
The even_numbers function returns a space-separated string of all positive numbers that are divisible by 2, up to and including the maximum that's passed into the function. For example, even_numbers(6) returns “2 4 6”. Fill in the blank to make this work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def even_numbers(maximum): | |
return_string = "" | |
for x in range(2, maximum + 1, 2): | |
return_string += str(x) + " " | |
return return_string.strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def even_numbers(maximum):
return_string=""
for x in range(2, maximum+1):
if x%2==0:
return_string+=str(x) +" "
return return_string.strip()
print(even_numbers(6)) # Should be 2 4 6
print(even_numbers(10)) # Should be 2 4 6 8 10
print(even_numbers(1)) # No numbers displayed
print(even_numbers(3)) # Should be 2
print(even_numbers(0)) # No numbers displayed