Problem with the "for" loop syntax

J

John Gordon

In said:
Hello guys...
I=B4m a begginer in Python, I'm doing a Hangman game, but I'm having troubl=
e with this blank space. I would be greatful if you help me. :)
Here's my code:

Snipplr says that link doesn't exist.
When I run the code it says: Invalid Syntax and this is the error:

http://i.imgur.com/ySoOZFR.png

I don't see anything obviously wrong with that code. Are you sure that's
a real blank space, and not some weird character that *looks* like a space?
 
D

Dave Angel

Hello guys...
I´m a begginer in Python, I'm doing a Hangman game, but I'm having trouble with this blank space. I would be greatful if you help me. :)

Here's my code:

http://snipplr.com/view/71581/hangman/

When I run the code it says: Invalid Syntax and this is the error:

http://i.imgur.com/jKYOPMY.png

http://i.imgur.com/ySoOZFR.png

If you want us to read it, put it in your message. Show at least a few
lines before and after the syntax error, and show the error itself, as
text of course. Use copy/paste.

Of course that assumes you're using a proper console/shell, and know how
to use it. So if you have to ask about that, start there.

In addition, specify the python version, and if appropriate, the OS and
its version.

Generally, you can find your own problem. Syntax errors that seem
confusing are frequently really on the line before the line in which
they're "discovered."
 
I

Ian Kelly

Hello guys...
I´m a begginer in Python, I'm doing a Hangman game, but I'm having trouble with this blank space. I would be greatful if you help me. :)

Here's my code:

http://snipplr.com/view/71581/hangman/

When I run the code it says: Invalid Syntax and this is the error:

http://i.imgur.com/jKYOPMY.png

http://i.imgur.com/ySoOZFR.png

Are you running this in Python 2 or Python 3? In Python 2, print is a
statement, not a function, and the end='' arguments would cause a
SyntaxError if you're not using the necessary __future__ import.
 
A

Arturo B

Mmmm....

Ok guys, thank you

I'm really sure that isn't a weird character, it is a space.

My Python version is 3.3.2, I've runed this code in Python 2.7.5, but it stills the same.

I've done what you said but it doesn't work.

Please Check it again here is better explained:

http://snipplr.com/view/71581/hangman/
 
J

Joshua Landau

Mmmm....

Ok guys, thank you

I'm really sure that isn't a weird character, it is a space.

My Python version is 3.3.2, I've runed this code in Python 2.7.5, but it stills the same.

I've done what you said but it doesn't work.

Please Check it again here is better explained:

http://snipplr.com/view/71581/hangman/

Listen;

1) Post the code in the EMail, not an external link.

2) Don't Top Post.

3) That link doesn't exist. There are so many good hosting sites; why
use one that doesn't work?

4) Give us a minimal example. This should be easy; just remove the
code above and the code below. This is also a valid debugging
technique.

5) Images? Really?
 
A

Arturo B

Sorry, I'm new in here

So, if you want to see the complete code I've fixed it:
http://www.smipple.net/snippet/a7xrturo/Hangman! :)

And here is the part of code that doesn't work:


#The error is marked in the whitespace between letter and in

def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord):
print (HANGMANPICS[len(missedLetters)])
print()

print('Missed letters: ', end='')

#Starts problem

for letter in missedLetters:

#Finishes problem

print(letter, end=' ')
print()

blanks = '_' * len(secretWord)

for i in range(len(secretWord)):
if secretWord in correctLetters:
blanks = blanks[:i] + secretWord + blanks[i+1:]

for letter in blanks:
print(letter, end=' ')
print()



When I press F5 (Run) I get a window that says: 'Invalid Syntax' and the whitespace between letter and in is in color red
 
C

Chris Angelico

Fixed, the problem was in
HANGMANPICS

I didn't open the brackets.

Thank you guys :)

General debugging tip: Syntax errors are sometimes discovered quite
some way below the actual cause. The easiest way to figure out what's
the real cause is to start cutting away unnecessary code until all
that's left is the tiniest part that still has the error. This is also
very helpful as a prerequisite to posting on a list like this, so even
if you can't find the problem yourself by this method (you often will,
though), it's well worth doing.

ChrisA
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top