-2

I am trying to execute the above code using Python 2.7. I get EOFError.

def perfectNumberCheck(num):
    sum = 0
    for i in range(1, num):
        if num % i == 0:
            sum = sum + i
    if sum == num:
        print('1')
    else:
        print('0')


num = int(raw_input('come on dude:'))
perfectNumberCheck(num)

I have no problem in Python 3 but need to submit the assignment in Python 2.

1 Answer 1

0

When your os automatically calls the script in the background, there is no STDIN into the script, thus it receives an unexpected end-of-file (because, technically, stdin=/dev/null , which will always give eof). As described here you can try the following part:

import sys
for line in sys.stdin:
    print line

sys.stdin = open('CON', 'r')
num = raw_input("come on dude:")
perectNumberCheck(num)
Sign up to request clarification or add additional context in comments.

1 Comment

i am still getting the same error. I have no problem in python 3 but need to submit the asssignment in python 2. plz help me.

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.