EOFError, even after trying the try and except block
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
|
show 2 more comments
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
How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop theinput()
(ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop theinput()
I get theKeyboardInterrupt
error, not theEOFError
.
– Gino Mempin
Jan 21 at 0:15
1
Thereturn
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
|
show 2 more comments
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
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
python-3.x eoferror
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 theinput()
(ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop theinput()
I get theKeyboardInterrupt
error, not theEOFError
.
– Gino Mempin
Jan 21 at 0:15
1
Thereturn
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
|
show 2 more comments
How are you testing this? What were you entering in the terminal prompt as int inputs and then to stop theinput()
(ex. Ctrl+C?)? I can't reproduce because if I use Ctrl+C to stop theinput()
I get theKeyboardInterrupt
error, not theEOFError
.
– Gino Mempin
Jan 21 at 0:15
1
Thereturn
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
|
show 2 more comments
1 Answer
1
active
oldest
votes
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())
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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())
add a comment |
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())
add a comment |
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())
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())
answered Jan 22 at 5:34
unlutunlut
891310
891310
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 theinput()
I get theKeyboardInterrupt
error, not theEOFError
.– 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