I just wrote my first Python program a guessing game and it exitswith an error I get this.

  • Thread starter Armando Montes De Oca
  • Start date
A

Armando Montes De Oca

Traceback (most recent call last):
File "Guessing_Game.py", line 32, in <module>
input (enter)
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
------------------
(program exited with code: 1)
This is the only place a string is used:
else:
print "Sorry you loose the game."
computernum = str(computernum)
print " The computers number was!"+ computernum
input (enter)
sys.exit(0)
Thank You,
 
C

Carlos Nepomuceno

Date: Wed, 5 Jun 2013 07:40:52 -0700
Subject: I just wrote my first Python program a guessing game and it exits with an error I get this.
From: (e-mail address removed)
To: (e-mail address removed)

Traceback (most recent call last):
File "Guessing_Game.py", line 32, in <module>
input (enter)
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
------------------
(program exited with code: 1)
This is the only place a string is used:
else:
print "Sorry you loose the game."
computernum = str(computernum)
print " The computers number was!"+ computernum
input (enter)

Did you declared an 'enter' variable? Because input() expects a string.
 
A

Armando Montes De Oca

Traceback (most recent call last):

File "Guessing_Game.py", line 32, in <module>

input (enter)

File "<string>", line 0

^

SyntaxError: unexpected EOF while parsing

------------------

(program exited with code: 1)

This is the only place a string is used:

else:

print "Sorry you loose the game."

computernum = str(computernum)

print " The computers number was!"+ computernum

input (enter)

sys.exit(0)
Yes I did declare and enter value it is:
enter = "Please Press Enter To Continue..."
 
A

Armando Montes De Oca

import random
import sys
enter = "Please Press Enter To Continue..."
print " Hello! Welcome to a Guessing game!"
print " Please Guess a number between 1 - 100"
computernum = random.randint (1, 100)
Guess1 = input ( "My First Guess Is: ")
if Guess1 == computernum:
print "You Win !"
input (enter)
sys.exit(0)
else:
print "Sorry, Try Again!"
print "You have Two guesses remaining!"
Guess2 = input("My Second Guess Is: ")
if Guess2 == computernum:
print "Wow, Congradulations YOU WIN!"
input (enter)
sys.exit(0)
else:
print "Sorry One more try!"
print "You have One final guess remaining!"
Guess3 = input (" My final guess is ")
if Guess3 == computernum:
print "Congradulations shit head"
input (enter)
sys.exit (0)
else:
print "Sorry you loose the game."
computernum = str(computernum)
print "The computers number was!" + computernum
input (enter)
sys.exit(0)
 
T

Tim Golden

Armando. Try this at a Python prompt, and just press Enter without
entering any text.

input("Please enter something:")


The trouble is that the beguilingly-named "input" function actually
*evaluates* what you type, ie it's the same as doing this:

eval("")

which, as you can see, gives the same error message. You're clearly
using Python 2.x as your prints are statements, so input has this
characteristic. Instead you should use raw_input:

raw_input(enter)

TJG
 
M

Mark Lawrence

I just post all my code I have for the guessing game.

Please post with some context so we don't have to go to other parts of
the thread to find out what you're talking about, thanks.

--
"Steve is going for the pink ball - and for those of you who are
watching in black and white, the pink is next to the green." Snooker
commentator 'Whispering' Ted Lowe.

Mark Lawrence
 
A

Armando Montes De Oca

Thank You now the program exits with:
(program exited with code: 0)
Press return to continue


Is there a way to get the line (program exited with code: 0) to say something

like: "The game will end now"

Press return to contine
 
Z

Zachary Ware

enter = "Please Press Enter To Continue..."

Hi Armando,

There are a few problems with your question. To be able to help you,
we really need to know your Python version, what OS you are using, how
you are running your script, and at what point you get the error in
question. Also, just a snippet of code from the middle of the script
is useless to us, we need to see a complete, runnable program that
shows your problem.

In this particular case, though, I can deduce a few things and, I
believe, answer your question.

First, your Python version. Judging by your use of 'print' as a
statement rather than a function, it looks like you're using Python 2,
probably 2.7. This is a big factor in your problem.

Second, when you get your error. I'm betting it's after you see
"Please Press Enter To Continue..." and have pressed 'enter'.

Now the kicker: I can reproduce your problem with the following
complete program:

# error_test.py
input('Press enter')
# end of error_test.py

The problem here is that you are using 'input()' in Python 2. In
Python 2, 'input()' is equivalent to 'eval(raw_input())', which means
that anything you give to 'input' will be evaluated in the current
scope, and this is a HUGE security hole. It can also cause serious
issues, such as you are having with your program: when you press enter
at the prompt, you pass '' (the empty string) to eval, which sees EOF
before it can actually evaluate anything, and so it raises a
SyntaxError. The simple fix here is to replace every occurance of
'input(' with 'raw_input(', or to make a step towards Python 3
compatibility, add this to the top of your program:

try:
input = raw_input
except NameError:
pass

Hope this helps,

Zach
 
A

Armando Montes De Oca

Thank You I will give it a try

I am using Linux Mint 14 Nadia
and my Python is with Geany 1.22 and I think it is python 2
 
A

Armando Montes De Oca

try:
input = raw_input
except NameError:
pass

This gave me the same output exited with code zero

Same with or without.

I am happy with the code 0 in it for now but if anyone knows with Geany in Linux Mint 14 Nadia what I can do to get it to say something nice and proper I would appreciate it for my next program.
 
Z

Zachary Ware

Thank You now the program exits with:
(program exited with code: 0)
Press return to continue


Is there a way to get the line (program exited with code: 0) to say something

like: "The game will end now"

Press return to contine

To whom are you replying? Please quote what (and who) you are
replying to to provide context.

As for how to change that line, it depends on how you're running the script.
 
J

Joel Goldstick

wrote:

To whom are you replying? Please quote what (and who) you are
replying to to provide context.

As for how to change that line, it depends on how you're running the
script.


The program exited with code: 0 is being provided by geany after your
program has run.

If instead you open up a terminal and type:
python your_program.py

You will run your program and get an error message from python. You can
get rid of the error message by using try/except, but you may not have
learned about that yet.

good luck
 
A

Armando Montes De Oca

Well I am replying to To whom it may concern at this point I am a bit lost.I posted all my code. I am not taking classes on this nor do I have a bookI followed a guy on You Tube. I am a student but I heard Python is a good language to learn in conjunction with C++ and Perl for example. I have taken Visual Basic 2010 last semester so keep thinking for me if you like if not when I can get a Python book or lesson. Joel Goldstick seems the more "professorly" so far by telling me the right thing of I have not learned something yet. Also with a name like Goldstick which seems Jewish to me. I wouldthink as a Gentile Heathen Jesus save us this would project a need for a good sex life.
 
A

Armando Montes De Oca

Not to make excuses as to my forum etiquette I apologize. I am half Cuban and simple. I meant no disrespect I like Mr. Goldstick's name. Maybe I can find the answer somewhere else true. However a simple code to close the program like in Visual Basic "Me.close" seems like something that should come easy to a program environment. sys.exit(0) for python is logical. I just get the line: program exited with code (0). I will Google the line in any case. You know in school I did well in English writing if that helps. I also can take the line out sys.exit(0). So I need a different line of code to close or to do something to make that line not appear. I also understand thatprogramming languages can be more complex to get somethings done.

Thank You all for your time.
apologies.
 
A

Armando Montes De Oca

Well I am sure this will end up a simple solution which is not solved by the geniuses with no sense of humor. Programmers are known for being odd nerds and I just got two of them. Goldstick Jesus what a couple of lazy minded nonsense. Your an ass hole.
 
M

Mark Lawrence

Well I am sure this will end up a simple solution which is not solved by the geniuses with no sense of humor. Programmers are known for being odd nerds and I just got two of them. Goldstick Jesus what a couple of lazy minded nonsense. Your an ass hole.

So that's three people at least within the last couple of weeks who
could have written "How to win friends and influence people".

--
"Steve is going for the pink ball - and for those of you who are
watching in black and white, the pink is next to the green." Snooker
commentator 'Whispering' Ted Lowe.

Mark Lawrence
 
D

Dennis Lee Bieber

Traceback (most recent call last):
File "Guessing_Game.py", line 32, in <module>
input (enter)
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
------------------
(program exited with code: 1)
This is the only place a string is used:
else:
print "Sorry you loose the game."

The word is "lose" ("loose" is when your T-shirt is three sizes too
big)
computernum = str(computernum)
print " The computers number was!"+ computernum
input (enter)

1) In Python 2.x this is dangerous, you probably want raw_input (in
3.x, it IS raw_input)
2) input is a function that returns data...

data = input()

3) Argument to input is a PROMPT string to be displayed, but you
didn't define "enter".
 
S

Steven D'Aprano

Traceback (most recent call last):
File "Guessing_Game.py", line 32, in <module>
input (enter)
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing


Your problem is that you should not be using input(), but raw_input()
instead.

Replace every call to input() to raw_input() instead, and this specific
problem will go away. It may reveal other bugs, but that's programming
for you.
 
A

Armando Montes De Oca

Yes Steven a C book I am reading has a quote "Every programmer is fluent in swearing" After my blow ups and confusion I am happy with my program anyway. I will get better at it eventually. I did change things to "raw_input" and works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top