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”.
Furthermore, the else statement gives a syntax error. I can't figure out the issue.
els
def even_numbers(maximum):
return_string = ""
for x in range(1,maximum):
x=x*2
return_string += str(x) + " "
if maximum%2==0:
x == maximum
break
else x == maximum:
break
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
'''
Aucun commentaire:
Enregistrer un commentaire