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 ___: 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

Respuesta :

Answer:

The correct form of the program in python is as follows

def even_numbers(maximum):

     return_string = ""  

     for x in range(1,maximum+1):

           if x % 2 == 0:

                 return_string+=str(x)+" "

     return return_string.strip()

Explanation:

This line defines the method

def even_numbers(maximum):

This line initializes return_string to an empty string

     return_string = ""  

This line iterates through variable maximum

     for x in range(1,maximum+1):

This line checks if the current number is even

           if x % 2 == 0:

If yes, the string is updated

                 return_string+=str(x)+" "

This line returns the full string of even numbers

    return return_string.strip()

When the method is tested with any of the following, it gives the desired result

print(even_numbers(6)), print(even_numbers(10)), print(even_numbers(1)), print(even_numbers(3)) and print(even_numbers(0))