Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code:
def even_number():
list = []
for n in range(0, 6):
if n % 2 == 0:
list.append(n)


print(even_number())

Right now, it just returns 'None'.But I would like to return the list of even number between 1 and 6.

What I have tried:

I have tried changing what I'm printing (e.g. even_number and n). Also, printing list returns '<class 'list'>
Posted
Updated 30-Jan-18 0:00am
v2

Try returning the value:
Python
def even_number():
  list = []
  for n in range(0, 6):
    if n % 2 == 0:
      list.append(n)
  return list

print(even_number())
 
Share this answer
 
for n in range(0,7):
  if(n%2 == 0):
    print(n)
 
Share this answer
 
Comments
[no name] 31-Jan-18 2:37am    
Let me know the reason to down vote?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900