Skip to content

Instantly share code, notes, and snippets.

@ayubmetah
Created December 20, 2020 07:09
Show Gist options
  • Save ayubmetah/f1067363a2cb92ee5d594ba3ac09cc5e to your computer and use it in GitHub Desktop.
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.
def even_numbers(maximum):
return_string = ""
for x in range(2, maximum + 1, 2):
return_string += str(x) + " "
return return_string.strip()
@maqboolkazmii
Copy link

def even_numbers(maximum):
return_string = ""
for x in range(2, maximum + 1, 2):
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

@Joaking95
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment