Computer Science, asked by Anonymous, 8 months ago

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

Answers

Answered by divyanshtiwarivk
0

Answer:

2-44+5+2+4+4+5+5+ is twy

Answered by himanshuneha0304
1

Answer:

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

Explanation:

for x in range(2,maximum+1,2): - Here initial 2 defines the start of range , maximum+1 tells us that last number of the range is incremented by 1 so that last number can be included in range , and last 2 tells that range will be iterated with interval of 2.

Similar questions