Alex Rivera | Logout

Python unexpected EOF while parsing

Asked 2011-02-22T05:04:33.060
86

Here's my python code. Could someone show me what's wrong with it.

while 1:
    date=input("Example: March 21 | What is the date? ")
    if date=="June 21":
        sd="23.5° North Latitude"
    if date=="March 21" | date=="September 21":
        sd="0° Latitude"
    if date=="December 21":
        sd="23.5° South Latitude"
    if sd:
        print sd

And Here's what happens:

>>> 
Example: March 21 | What is the date? 
Traceback (most recent call last):
  File "C:\Users\Daniel\Desktop\Solar Declination Calculater.py", line 2, in <module>
    date=input("Example: March 21 | What is the date? ")
  File "<string>", line 0
    
   ^
SyntaxError: unexpected EOF while parsing
>>> 
Edit
Report

1 Answer

0

What you can try is writing your code as normal for python using the normal input command. However the trick is to add at the beginning of you program the command input=raw_input.

Now all you have to do is disable (or enable) depending on if you're running in Python/IDLE or Terminal. You do this by simply adding '#' when needed.

Switched off for use in Python/IDLE

    #input=raw_input 

And of course switched on for use in terminal.

    input=raw_input 

I'm not sure if it will always work, but its a possible solution for simple programs or scripts.

answered 2013-06-23T16:21:17.807

Your Answer