EOF problem with ENTER
clp2 at rebertia.com
Fri Jun 12 08:28:20 CEST 2009
On Thu, Jun 11, 2009 at 11:17 PM, Prasoon<prasoonthegreat at gmail.com> wrote:
> I am new to python....
> I have written the following program in python.It is the solution of
> problem ETF in SPOJ.....
> #Euler Totient Function
> from math import sqrt
> def etf(n):
> i,res =2,n
> return res
> def main():
> print str(etf(x))
> if __name__ == "__main__":
> The problem with my code is that whenever I press an extra "Enter"
> button instead of getting the cursor moved to the next line.....I get
> an error
> _SyntaxError- EOF while parsing and the program terminates.........._
> How should the code be modified so that even after pressing an extra
> "Enter" button the cursor get moved to the next line instead to
> throwing an exception......
Use raw_input() instead of input() [at least until you switch to Python 3.x].
input() does an implicit eval() of the keyboard input, which is (in
part) causing your problem.
Note that you'll need to explicitly convert the string raw_input()
reads in using either int() or float() as appropriate.
Still, you can't just enter extra lines and expect the program to
automatically ignore them. You'll have to write the extra code
yourself to handle empty input from the user.
More information about the Python-list