1

In this program I am attempting to have it so that the variable integer_enter within the while loop will keep being assigned integers until a 0 is entered in to the input. Every time I run the code I get an EOF error on the "integer_enter= int(input())" line. Why would that be? There is nothing wrong with defining a variable within a while loop so why am I getting that error?

Code for reference:

list_num = [ ]
count_even = 0

loop_condition= True

while(loop_condition == True):
    integer_enter= int(input())
    integer_append= list_num.append(integer_enter)
    if(integer_enter % 2 == 0):
        count_even += 1
    elif(integer_enter == 0):
        loop_condition = False 




print('The number of even integers is %d' % count_even)

print(list_num)
3
  • The while loop would never stop because 0 % 2 == 0 Commented Oct 26, 2016 at 3:50
  • Only if the integer_enter equaled a positive number, right? Commented Oct 26, 2016 at 3:52
  • BTW, integer_append is None will always be true because list.append doesn't return anything. Commented Oct 26, 2016 at 4:00

1 Answer 1

1

You need to modify your condition for the loop termination. You need to make sure that your if is not executed when the integer_enter is 0. This is a working link to your code.

list_num = [ ]
count_even = 0

loop_condition= True

while(loop_condition == True):
    integer_enter= int(input())
    integer_append= list_num.append(integer_enter)
    if(integer_enter % 2 == 0 and integer_enter != 0):
        count_even += 1
    elif(integer_enter == 0):
        loop_condition = False 




print('The number of even integers is %d' % count_even)

print(list_num)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I forgot that 0 % 2 would also equal 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.