EOF while taking inputs using map in python
up vote
-1
down vote
favorite
Im trying to solve this problem on HackerRank
But Im constantly getting this error while scanning the elements of a list, as an input in a single line seperated by whitespaces
Here is a sample of my code:
n,m=input().split()
n=int(n)
m=int(m)
for i in range(n):
list1=map(int,input().split())
for j in range(m):
try:
list2= map(int,input().split())
except EOFError as e:
print(e)
minimum=max(list1)
maximum=min(list2)
count=0
for k in range(minimum,maximum+1):
flag=0
for i in range(n):
if(k%list1[i]!=0):
flag+=1
break
if(flag!=1):
for i in range(m):
if(list2[i]%k!=0):
flag+=1
break
if(flag==0):
count+=1
print(count)
And here is the error which Im Facing
Traceback (most recent call last):
File "solution.py", line 12, in
maximum=min(list2)
NameError: name 'list2' is not defined
EOF when reading a line
EOF when reading a line
EOF when reading a line`
python python-3.x error-handling runtimeexception
add a comment |
up vote
-1
down vote
favorite
Im trying to solve this problem on HackerRank
But Im constantly getting this error while scanning the elements of a list, as an input in a single line seperated by whitespaces
Here is a sample of my code:
n,m=input().split()
n=int(n)
m=int(m)
for i in range(n):
list1=map(int,input().split())
for j in range(m):
try:
list2= map(int,input().split())
except EOFError as e:
print(e)
minimum=max(list1)
maximum=min(list2)
count=0
for k in range(minimum,maximum+1):
flag=0
for i in range(n):
if(k%list1[i]!=0):
flag+=1
break
if(flag!=1):
for i in range(m):
if(list2[i]%k!=0):
flag+=1
break
if(flag==0):
count+=1
print(count)
And here is the error which Im Facing
Traceback (most recent call last):
File "solution.py", line 12, in
maximum=min(list2)
NameError: name 'list2' is not defined
EOF when reading a line
EOF when reading a line
EOF when reading a line`
python python-3.x error-handling runtimeexception
1
Why are you doing things n or m times, which do not depend on i or j respectively?
– SpghttCd
Nov 11 at 16:08
And what are you achieving here in a program which wants the user three times to input sth, two times even in loops, throwing everything but the last input away...??? I think you didn't understandinput()
completely...
– SpghttCd
Nov 11 at 16:13
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Im trying to solve this problem on HackerRank
But Im constantly getting this error while scanning the elements of a list, as an input in a single line seperated by whitespaces
Here is a sample of my code:
n,m=input().split()
n=int(n)
m=int(m)
for i in range(n):
list1=map(int,input().split())
for j in range(m):
try:
list2= map(int,input().split())
except EOFError as e:
print(e)
minimum=max(list1)
maximum=min(list2)
count=0
for k in range(minimum,maximum+1):
flag=0
for i in range(n):
if(k%list1[i]!=0):
flag+=1
break
if(flag!=1):
for i in range(m):
if(list2[i]%k!=0):
flag+=1
break
if(flag==0):
count+=1
print(count)
And here is the error which Im Facing
Traceback (most recent call last):
File "solution.py", line 12, in
maximum=min(list2)
NameError: name 'list2' is not defined
EOF when reading a line
EOF when reading a line
EOF when reading a line`
python python-3.x error-handling runtimeexception
Im trying to solve this problem on HackerRank
But Im constantly getting this error while scanning the elements of a list, as an input in a single line seperated by whitespaces
Here is a sample of my code:
n,m=input().split()
n=int(n)
m=int(m)
for i in range(n):
list1=map(int,input().split())
for j in range(m):
try:
list2= map(int,input().split())
except EOFError as e:
print(e)
minimum=max(list1)
maximum=min(list2)
count=0
for k in range(minimum,maximum+1):
flag=0
for i in range(n):
if(k%list1[i]!=0):
flag+=1
break
if(flag!=1):
for i in range(m):
if(list2[i]%k!=0):
flag+=1
break
if(flag==0):
count+=1
print(count)
And here is the error which Im Facing
Traceback (most recent call last):
File "solution.py", line 12, in
maximum=min(list2)
NameError: name 'list2' is not defined
EOF when reading a line
EOF when reading a line
EOF when reading a line`
python python-3.x error-handling runtimeexception
python python-3.x error-handling runtimeexception
asked Nov 11 at 16:03
YASH MATE
1
1
1
Why are you doing things n or m times, which do not depend on i or j respectively?
– SpghttCd
Nov 11 at 16:08
And what are you achieving here in a program which wants the user three times to input sth, two times even in loops, throwing everything but the last input away...??? I think you didn't understandinput()
completely...
– SpghttCd
Nov 11 at 16:13
add a comment |
1
Why are you doing things n or m times, which do not depend on i or j respectively?
– SpghttCd
Nov 11 at 16:08
And what are you achieving here in a program which wants the user three times to input sth, two times even in loops, throwing everything but the last input away...??? I think you didn't understandinput()
completely...
– SpghttCd
Nov 11 at 16:13
1
1
Why are you doing things n or m times, which do not depend on i or j respectively?
– SpghttCd
Nov 11 at 16:08
Why are you doing things n or m times, which do not depend on i or j respectively?
– SpghttCd
Nov 11 at 16:08
And what are you achieving here in a program which wants the user three times to input sth, two times even in loops, throwing everything but the last input away...??? I think you didn't understand
input()
completely...– SpghttCd
Nov 11 at 16:13
And what are you achieving here in a program which wants the user three times to input sth, two times even in loops, throwing everything but the last input away...??? I think you didn't understand
input()
completely...– SpghttCd
Nov 11 at 16:13
add a comment |
active
oldest
votes
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',
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%2f53250546%2feof-while-taking-inputs-using-map-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53250546%2feof-while-taking-inputs-using-map-in-python%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
1
Why are you doing things n or m times, which do not depend on i or j respectively?
– SpghttCd
Nov 11 at 16:08
And what are you achieving here in a program which wants the user three times to input sth, two times even in loops, throwing everything but the last input away...??? I think you didn't understand
input()
completely...– SpghttCd
Nov 11 at 16:13