0

I need a python code that collects all even numbers separately, odd numbers separately and displaying into two separate totals. The range of numbers is 1-20

I am new to this language and I keep getting syntax errors, invalid statement errors etc.. So it would be great if you can write a description about the code as well.

Thanks in advance.

4
Contributors
3
Replies
32
Views
3 Years
Discussion Span
Last Post by bryann
0
even_list = []
odd_list = []
li = range(1,21)
for i in range(len(li)):
    if i/2 == 0 :
        even_list.append(li[i])
    else :
        odd_list.append(li[i])
print even_list
print odd_list
0

MFS NCCCC
please show us what you have done.
Letting someone else write your homework for you will not allow you to learn much.

0

Mohit3 i think your if statement to find even numbers is wrong as any number of 2 or greater divided by 2 is going to give a higer result than 0.
You need to use modulo to find the numbers that are divisible exactly by 2. In python its %

Edited by bryann

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.