SyntaxError: unexpected EOF while parsing in python - python

I am getting the above error in python.
w=[]
h=[]
l=int(input())
t=int(input())
for i in range(t):
n=raw_input()
w.append(n)
n=int(input())
h.append(n)
for i in range(t):
if w<l and h<l:
print ("UPLOAD ANOTHER")
elif w>l and h>l and w!=h:
print ("CROP IT")
elif w>=l and h>=l and w==h:
print("ACCEPTED")

You probably given a empty input or '\n' for the n=int(input()) part. Try to give the number as input.
put this line in your terminal
x = int(input()). and give empty input, (just tap enter). vola..
SyntaxError: unexpected EOF while parsing

You might be running the script on some online IDE. This also appeared to me while I was submitting my solution. The best way to deal with this is don't run your script on online ide rather directly submit it.
If the answer is correct it would get accepted else show the wrong answer.

Related

Python3 : EOF Error while taking input on GUVI

This is my code in python3:
import heapq
myQueue = []
n = raw_input()
try:
num = int(n)
if num<=100000 :
arr = input().split()
for i in range(num):
heapq.heappush(myQueue, arr[i])
print(myQueue[0])
except (NameError, ValueError):
print("Wrong Input, N should be under 100000")
except IndexError:
print("Inputs is less than actually required")
except EOFError:
print ("Error: EOF or empty input!")
I am trying to implement priority queue.
But I am facing this EOF Error while solving this problem on GUVI.
Output:
Error: EOF or empty input!
The tried to catch the error using except EOFError, but that will just make my program run but does not solve input problem right.
I even tried to run this piece of code on Sublime text editor as well as Vs code,
where it runs just fine, Correct Output.
I don't understand, is there a problem in my code or That Online Platform.
I even tried to search the answer on their Q&A platform of GUVI, I found similar question but no one has answered it.
And this is not just for this piece of Code but I found the same error for many before.
Could ANYONE help me, Please!
Thanking you in advance.. :)
EOF error occurs if the input is not provided.
In case of most of the online compilers you need to provide the inputs before running the code.
With that said, while your are trying to access the input via raw_input() there will be no input supplied resulting in the above error.
To avoid this, error supply inputs before running your code like below
Also, I can notice that you are using raw_input() and input(). Please note that raw_input() can be used if you are using Python 2 and input() if you are using python 3 correspondingly.

User inputs reserved keyword in Python. There happens an error

I am working on a simple program (just for a joke). A program wants that the user input yes or no (it can be in different languages). But when he enters a reserved word (i. e. keyword) there happens an error because this keyword does some bugs in the code.
My truncated code (maybe it seems unclear because it's truncated):
x = input('Enter yes or no (you can do this in different languages...) ')
x = x.lower()
answersYes = ['yes','si','oui','ioe','inde','tak','ja','da']
answersNo = ['no','ayi','che','leai','nie','ne','nein']
if ' ' in x:
print('Input just one word!')
else:
if x in answersYes:
print('You enteres YES!')
elif x in answersNo:
print('You enteres NO!')
else:
print('Sorry, but this isn\'t YES nor NO!')
I have done some googling around, but there was no luck yet.
Thank you a lot for any answer!
P.S.
Just one little note:
When I have run the upper script in Python in basic Python IDLE, there wasn't any error, but when I have run this in Spyder, there displayed this message (when I typed 'yes in no' ("in" is a reserved word)):
File "<ipython-input-49-d1e48c3ddecb>", line 1
yes in no
^
SyntaxError: invalid syntax
I don't get an error. Make sure your spyder is python3-configured or try running with python3 file.py
You can also try replacing input() with raw_input()

Python3 NZEC Error

This piece of code is supposed to find account balance after withdraw from bank(fee=0.5).
wd,ac=raw_input().split(" ")
wd=int(wd)
ac=float(ac)
if(ac<wd):
print(ac)
elif(wd%5==0):
if(ac>wd+0.50):
print(ac-wd-0.50)
else:
print(ac)
else:
print(ac)
I got a Runtime NZEC Error while submitting on codechef. I am newbie and had searched for resolve and had used split(" ") in place of int(input()), which I had tried previously, but the problem still occurs.
Geeksforgeeks says:
"In python, generally multiple inputs are separated by commas and we read them using input() or int(input()), but most of the online coding platforms while testing gives input separated by space and in those cases int(input()) is not able to read the input properly and shows error like NZEC"
Given that I've tried to account for that... What is wrong with my code?
It looks like an error with your raw_input statement. Remember that, in python 3, raw_input doesn't exist any more. If you changed it from raw_input to input, then the code works just fine.

Invalid Syntax and I don't know why

I have this code in Python 3. I am a begginer so links to good sites will also be helpful. Anyway my goal is to find two duplicated numbers in a list and then find the number of elements between them. When I run my module it comes up as invalid syntax with no explanation. All it said was Invalid Syntax with nothing else. Any help is appreciated.
def pirate_list(thelist):
duplicate = set()
duplicate_add = duplicate.add
f = []
for i in thelist:
if i in duplicate or duplicate_add(i):
f.append(i)
print (f)
f.reverse()
print(f)
break
else:
f.append(i)
print ("fail")
pirate_list([6,1,0,2,1,6])
def count_list(f):
duplicate = set()
duplicate_add = duplicate.add
s = []
for x in f:
if x in duplicate or duplicate_add(x):
s.append(x)
print len(s)
break
else:
s.append(x)
count_list(f)
The text under each def statement should be indented.
The last line refers to countlist which is not defined, and f which is defined inside a different function.
The def statements are to be indented. countlist should be count_list, on the last line as Jonathon Clede said.
Make it a practice to learn to understand error messages. They are vital to debugging your code. Even though there was no real error message this time, be sure to do it other times. SyntaxError by itself is usually caused by a pesky error like this indentation one.
If it is python2 code, then the only error I find is the undefined variable f in the last line.
If it is python3 code, then you must change print len(s) to print(len(s)) as print is a function in python3 and not a separate statement keyword.
Thanks for all the help. It was a rookie mistake forgetting parentheses for the print len(s) and also bringing the f list outside the functions.

while loop in python gives syntax error

I am very new to python, this is my first program that I am trying.
This function reads the password from the standard input.
def getPassword() :
passwordArray =[]
while 1:
char = sys.stdin.read(1)
if char == '\\n':
break
passwordArray.append(char)
return passwordArray
print (username)
print (URL)
getting this error:
Problem invoking WLST - Traceback (innermost last):
(no code object) at line 0
File "/scratch/aime/work/stmp/wlstCommand.py", line 10
while 1:
^
SyntaxError: invalid syntax
Your indentation is not correct. Your while should be indented the same as the line above it.
Python uses indentation to "separate" stuff and the thing with that is you need to have the same kind of indentation across the file. Having a fixed kind of indentation in the code you write is good practice. You might want to consider a tab or four spaces(The later being the suggestion in the PEP8 style guide)
Python is sensitive and depended on indentation. If it complains "invalid Format", that is better than "invalid syntax".

Categories