I made a program in which the user enters some integers and python displays how many even and odd numbers you entered. The code is the following:

ev_od_list = [] even = [] odd = [] number = int(input("Enter an integer(entering 0 would end the process): ")) while number != 0: number = int(input("Enter an integer(entering 0 would end the process): ")) ev_od_list.append(number) for i in ev_od_list: if i % 2 == 0: even.append(i) even.remove(0) print("The number of even numbers you entered is:", len(even)) for j in ev_od_list: if j % 2 != 0: odd.append(j) print(ev_od_list) print("The number of odd numbers you entered is:", len(odd))

And the output…

Enter an integer(entering 0 would end the process): 1 Enter an integer(entering 0 would end the process): 2 Enter an integer(entering 0 would end the process): 3 Enter an integer(entering 0 would end the process): 4 Enter an integer(entering 0 would end the process): 5 Enter an integer(entering 0 would end the process): 6 Enter an integer(entering 0 would end the process): 7 Enter an integer(entering 0 would end the process): 8 Enter an integer(entering 0 would end the process): 9 Enter an integer(entering 0 would end the process): 10 Enter an integer(entering 0 would end the process): 0 The number of even numbers you entered is: 5 [2, 3, 4, 5, 6, 7, 8, 9, 10, 0] The number of odd numbers you entered is: 4

In the second last line, you may notice that 1 has been removed from the list automatically. So, why is this happening?

## Answer

The reason is you have a first call to `input()`

which is overwritten by another call of `input()`

and append the number after the second `input()`

call. Here is the working code with much optimisations:

even = [] odd = [] number = int(input("Enter an integer(entering 0 would end the process): ")) while number != 0: if number != 0: if number % 2 == 0: even.append(number) else: odd.append(number) number = int(input("Enter an integer(entering 0 would end the process): ")) print("The number of even numbers you entered is:", len(even)) print("The number of odd numbers you entered is:", len(odd))