EOFError, even after trying the try and except block












1















Could anyone please state the reason why it is showing. I acknowledge it as python after reading the input states that there is nothing to read.




Python 3.6




    #!/bin/python3

import math
import os
import random
import re
import sys

while True:
try:
N = int(input())
except EOFError:
return
#N = int(input())


if N % 2 != 0:
print("Wierd")
elif N % 2 == 0 and N in range(2, 6):
print("Not Wierd")
elif N % 2 == 0 and N in range(6, 21):
print("Wierd")
elif N % 2 == 0 and N > 20:
print("Wierd")



if __name__ == '__main__':
N = int(input())


the error statement



Traceback (most recent call last):
File "solution.py", line 27, in <module>
N = int(input())
EOFError: EOF when reading a line
Blockquote









share|improve this question

























  • How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop the input() (ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop the input() I get the KeyboardInterrupt error, not the EOFError.

    – Gino Mempin
    Jan 21 at 0:15








  • 1





    The return line looks strange... Where's the function?

    – iBug
    Jan 22 at 5:24











  • Hi @GinoMempin, Testing is done itself in the code given by the website editor as stub code. Regarding this, the input is stdin and in the same way stdout. [hackerrank.com/challenges/30-conditional-statements/problem] . Thanks

    – Vaitesh Selvaraj
    Jan 22 at 5:25











  • @iBug, I too had the same intriguing question before trying the return. But a fellow [stackoverflow.com/a/42891677/10255905] had answered to similar question to use return to make it return nothing when EOF exception error comes.

    – Vaitesh Selvaraj
    Jan 22 at 5:31






  • 1





    +1 @GinoMempin, Well mate!! it did worked. initially i thought not to mess with the stub code as they have to test the code i have coded inside. but it turns out that it was indeed a function.

    – Vaitesh Selvaraj
    Jan 22 at 8:38
















1















Could anyone please state the reason why it is showing. I acknowledge it as python after reading the input states that there is nothing to read.




Python 3.6




    #!/bin/python3

import math
import os
import random
import re
import sys

while True:
try:
N = int(input())
except EOFError:
return
#N = int(input())


if N % 2 != 0:
print("Wierd")
elif N % 2 == 0 and N in range(2, 6):
print("Not Wierd")
elif N % 2 == 0 and N in range(6, 21):
print("Wierd")
elif N % 2 == 0 and N > 20:
print("Wierd")



if __name__ == '__main__':
N = int(input())


the error statement



Traceback (most recent call last):
File "solution.py", line 27, in <module>
N = int(input())
EOFError: EOF when reading a line
Blockquote









share|improve this question

























  • How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop the input() (ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop the input() I get the KeyboardInterrupt error, not the EOFError.

    – Gino Mempin
    Jan 21 at 0:15








  • 1





    The return line looks strange... Where's the function?

    – iBug
    Jan 22 at 5:24











  • Hi @GinoMempin, Testing is done itself in the code given by the website editor as stub code. Regarding this, the input is stdin and in the same way stdout. [hackerrank.com/challenges/30-conditional-statements/problem] . Thanks

    – Vaitesh Selvaraj
    Jan 22 at 5:25











  • @iBug, I too had the same intriguing question before trying the return. But a fellow [stackoverflow.com/a/42891677/10255905] had answered to similar question to use return to make it return nothing when EOF exception error comes.

    – Vaitesh Selvaraj
    Jan 22 at 5:31






  • 1





    +1 @GinoMempin, Well mate!! it did worked. initially i thought not to mess with the stub code as they have to test the code i have coded inside. but it turns out that it was indeed a function.

    – Vaitesh Selvaraj
    Jan 22 at 8:38














1












1








1








Could anyone please state the reason why it is showing. I acknowledge it as python after reading the input states that there is nothing to read.




Python 3.6




    #!/bin/python3

import math
import os
import random
import re
import sys

while True:
try:
N = int(input())
except EOFError:
return
#N = int(input())


if N % 2 != 0:
print("Wierd")
elif N % 2 == 0 and N in range(2, 6):
print("Not Wierd")
elif N % 2 == 0 and N in range(6, 21):
print("Wierd")
elif N % 2 == 0 and N > 20:
print("Wierd")



if __name__ == '__main__':
N = int(input())


the error statement



Traceback (most recent call last):
File "solution.py", line 27, in <module>
N = int(input())
EOFError: EOF when reading a line
Blockquote









share|improve this question
















Could anyone please state the reason why it is showing. I acknowledge it as python after reading the input states that there is nothing to read.




Python 3.6




    #!/bin/python3

import math
import os
import random
import re
import sys

while True:
try:
N = int(input())
except EOFError:
return
#N = int(input())


if N % 2 != 0:
print("Wierd")
elif N % 2 == 0 and N in range(2, 6):
print("Not Wierd")
elif N % 2 == 0 and N in range(6, 21):
print("Wierd")
elif N % 2 == 0 and N > 20:
print("Wierd")



if __name__ == '__main__':
N = int(input())


the error statement



Traceback (most recent call last):
File "solution.py", line 27, in <module>
N = int(input())
EOFError: EOF when reading a line
Blockquote






python-3.x eoferror






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 22 at 5:19







Vaitesh Selvaraj

















asked Jan 20 at 9:46









Vaitesh SelvarajVaitesh Selvaraj

104




104













  • How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop the input() (ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop the input() I get the KeyboardInterrupt error, not the EOFError.

    – Gino Mempin
    Jan 21 at 0:15








  • 1





    The return line looks strange... Where's the function?

    – iBug
    Jan 22 at 5:24











  • Hi @GinoMempin, Testing is done itself in the code given by the website editor as stub code. Regarding this, the input is stdin and in the same way stdout. [hackerrank.com/challenges/30-conditional-statements/problem] . Thanks

    – Vaitesh Selvaraj
    Jan 22 at 5:25











  • @iBug, I too had the same intriguing question before trying the return. But a fellow [stackoverflow.com/a/42891677/10255905] had answered to similar question to use return to make it return nothing when EOF exception error comes.

    – Vaitesh Selvaraj
    Jan 22 at 5:31






  • 1





    +1 @GinoMempin, Well mate!! it did worked. initially i thought not to mess with the stub code as they have to test the code i have coded inside. but it turns out that it was indeed a function.

    – Vaitesh Selvaraj
    Jan 22 at 8:38



















  • How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop the input() (ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop the input() I get the KeyboardInterrupt error, not the EOFError.

    – Gino Mempin
    Jan 21 at 0:15








  • 1





    The return line looks strange... Where's the function?

    – iBug
    Jan 22 at 5:24











  • Hi @GinoMempin, Testing is done itself in the code given by the website editor as stub code. Regarding this, the input is stdin and in the same way stdout. [hackerrank.com/challenges/30-conditional-statements/problem] . Thanks

    – Vaitesh Selvaraj
    Jan 22 at 5:25











  • @iBug, I too had the same intriguing question before trying the return. But a fellow [stackoverflow.com/a/42891677/10255905] had answered to similar question to use return to make it return nothing when EOF exception error comes.

    – Vaitesh Selvaraj
    Jan 22 at 5:31






  • 1





    +1 @GinoMempin, Well mate!! it did worked. initially i thought not to mess with the stub code as they have to test the code i have coded inside. but it turns out that it was indeed a function.

    – Vaitesh Selvaraj
    Jan 22 at 8:38

















How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop the input() (ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop the input() I get the KeyboardInterrupt error, not the EOFError.

– Gino Mempin
Jan 21 at 0:15







How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop the input() (ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop the input() I get the KeyboardInterrupt error, not the EOFError.

– Gino Mempin
Jan 21 at 0:15






1




1





The return line looks strange... Where's the function?

– iBug
Jan 22 at 5:24





The return line looks strange... Where's the function?

– iBug
Jan 22 at 5:24













Hi @GinoMempin, Testing is done itself in the code given by the website editor as stub code. Regarding this, the input is stdin and in the same way stdout. [hackerrank.com/challenges/30-conditional-statements/problem] . Thanks

– Vaitesh Selvaraj
Jan 22 at 5:25





Hi @GinoMempin, Testing is done itself in the code given by the website editor as stub code. Regarding this, the input is stdin and in the same way stdout. [hackerrank.com/challenges/30-conditional-statements/problem] . Thanks

– Vaitesh Selvaraj
Jan 22 at 5:25













@iBug, I too had the same intriguing question before trying the return. But a fellow [stackoverflow.com/a/42891677/10255905] had answered to similar question to use return to make it return nothing when EOF exception error comes.

– Vaitesh Selvaraj
Jan 22 at 5:31





@iBug, I too had the same intriguing question before trying the return. But a fellow [stackoverflow.com/a/42891677/10255905] had answered to similar question to use return to make it return nothing when EOF exception error comes.

– Vaitesh Selvaraj
Jan 22 at 5:31




1




1





+1 @GinoMempin, Well mate!! it did worked. initially i thought not to mess with the stub code as they have to test the code i have coded inside. but it turns out that it was indeed a function.

– Vaitesh Selvaraj
Jan 22 at 8:38





+1 @GinoMempin, Well mate!! it did worked. initially i thought not to mess with the stub code as they have to test the code i have coded inside. but it turns out that it was indeed a function.

– Vaitesh Selvaraj
Jan 22 at 8:38












1 Answer
1






active

oldest

votes


















0














return only works when you are inside a function and you want to exit from that function. In this case you just want to terminate your while loop so your should use break keyword.



Also in given question, you just need to read a single integer (I guess you are working on something different?)



import math
import os
import random
import re
import sys

while True:
try:
N = int(input())
except EOFError:
break
#N = int(input())


if N % 2 != 0:
print("Wierd")
elif N % 2 == 0 and N in range(2, 6):
print("Not Wierd")
elif N % 2 == 0 and N in range(6, 21):
print("Wierd")
elif N % 2 == 0 and N > 20:
print("Wierd")



if __name__ == '__main__':
N = int(input())





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275223%2feoferror-even-after-trying-the-try-and-except-block%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    return only works when you are inside a function and you want to exit from that function. In this case you just want to terminate your while loop so your should use break keyword.



    Also in given question, you just need to read a single integer (I guess you are working on something different?)



    import math
    import os
    import random
    import re
    import sys

    while True:
    try:
    N = int(input())
    except EOFError:
    break
    #N = int(input())


    if N % 2 != 0:
    print("Wierd")
    elif N % 2 == 0 and N in range(2, 6):
    print("Not Wierd")
    elif N % 2 == 0 and N in range(6, 21):
    print("Wierd")
    elif N % 2 == 0 and N > 20:
    print("Wierd")



    if __name__ == '__main__':
    N = int(input())





    share|improve this answer




























      0














      return only works when you are inside a function and you want to exit from that function. In this case you just want to terminate your while loop so your should use break keyword.



      Also in given question, you just need to read a single integer (I guess you are working on something different?)



      import math
      import os
      import random
      import re
      import sys

      while True:
      try:
      N = int(input())
      except EOFError:
      break
      #N = int(input())


      if N % 2 != 0:
      print("Wierd")
      elif N % 2 == 0 and N in range(2, 6):
      print("Not Wierd")
      elif N % 2 == 0 and N in range(6, 21):
      print("Wierd")
      elif N % 2 == 0 and N > 20:
      print("Wierd")



      if __name__ == '__main__':
      N = int(input())





      share|improve this answer


























        0












        0








        0







        return only works when you are inside a function and you want to exit from that function. In this case you just want to terminate your while loop so your should use break keyword.



        Also in given question, you just need to read a single integer (I guess you are working on something different?)



        import math
        import os
        import random
        import re
        import sys

        while True:
        try:
        N = int(input())
        except EOFError:
        break
        #N = int(input())


        if N % 2 != 0:
        print("Wierd")
        elif N % 2 == 0 and N in range(2, 6):
        print("Not Wierd")
        elif N % 2 == 0 and N in range(6, 21):
        print("Wierd")
        elif N % 2 == 0 and N > 20:
        print("Wierd")



        if __name__ == '__main__':
        N = int(input())





        share|improve this answer













        return only works when you are inside a function and you want to exit from that function. In this case you just want to terminate your while loop so your should use break keyword.



        Also in given question, you just need to read a single integer (I guess you are working on something different?)



        import math
        import os
        import random
        import re
        import sys

        while True:
        try:
        N = int(input())
        except EOFError:
        break
        #N = int(input())


        if N % 2 != 0:
        print("Wierd")
        elif N % 2 == 0 and N in range(2, 6):
        print("Not Wierd")
        elif N % 2 == 0 and N in range(6, 21):
        print("Wierd")
        elif N % 2 == 0 and N > 20:
        print("Wierd")



        if __name__ == '__main__':
        N = int(input())






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 22 at 5:34









        unlutunlut

        891310




        891310
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275223%2feoferror-even-after-trying-the-try-and-except-block%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage