Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48753 > unrolled thread

Problem with the "for" loop syntax

Started byarturo balbuena <a7xrturodev@gmail.com>
First post2013-06-19 14:14 -0700
Last post2013-06-20 11:09 +1000
Articles 9 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  Problem with the "for" loop syntax arturo balbuena <a7xrturodev@gmail.com> - 2013-06-19 14:14 -0700
    Re: Problem with the "for" loop syntax John Gordon <gordon@panix.com> - 2013-06-19 21:30 +0000
    Re: Problem with the "for" loop syntax Dave Angel <davea@davea.name> - 2013-06-19 17:32 -0400
    Re: Problem with the "for" loop syntax Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-19 16:35 -0600
    Re: Problem with the "for" loop syntax Arturo B <a7xrturodev@gmail.com> - 2013-06-19 15:53 -0700
      Re: Problem with the "for" loop syntax Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-20 00:15 +0100
    Re: Problem with the "for" loop syntax Arturo B <a7xrturodev@gmail.com> - 2013-06-19 17:32 -0700
    Re: Problem with the "for" loop syntax Arturo B <a7xrturodev@gmail.com> - 2013-06-19 18:02 -0700
      Re: Problem with the "for" loop syntax Chris Angelico <rosuav@gmail.com> - 2013-06-20 11:09 +1000

#48753 — Problem with the "for" loop syntax

Fromarturo balbuena <a7xrturodev@gmail.com>
Date2013-06-19 14:14 -0700
SubjectProblem with the "for" loop syntax
Message-ID<18f427ef-7a9a-413d-a824-65c9df430db3@googlegroups.com>
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


Thank you guys :)

[toc] | [next] | [standalone]


#48754

FromJohn Gordon <gordon@panix.com>
Date2013-06-19 21:30 +0000
Message-ID<kpt7ug$kio$1@reader1.panix.com>
In reply to#48753
In <18f427ef-7a9a-413d-a824-65c9df430db3@googlegroups.com> arturo balbuena <a7xrturodev@gmail.com> writes:

> 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:

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

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/jKYOPMY.png

> 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?

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#48755

FromDave Angel <davea@davea.name>
Date2013-06-19 17:32 -0400
Message-ID<mailman.3598.1371677588.3114.python-list@python.org>
In reply to#48753
On 06/19/2013 05:14 PM, arturo balbuena wrote:
> 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."


-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#48756

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-06-19 16:35 -0600
Message-ID<mailman.3599.1371681370.3114.python-list@python.org>
In reply to#48753
On Wed, Jun 19, 2013 at 3:14 PM, arturo balbuena <a7xrturodev@gmail.com> wrote:
> 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.

[toc] | [prev] | [next] | [standalone]


#48757

FromArturo B <a7xrturodev@gmail.com>
Date2013-06-19 15:53 -0700
Message-ID<fb39cbdb-2eff-4386-a8e6-0582c51f8f87@googlegroups.com>
In reply to#48753
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/

[toc] | [prev] | [next] | [standalone]


#48760

FromJoshua Landau <joshua.landau.ws@gmail.com>
Date2013-06-20 00:15 +0100
Message-ID<mailman.3602.1371683757.3114.python-list@python.org>
In reply to#48757
On 19 June 2013 23:53, Arturo B <a7xrturodev@gmail.com> wrote:
> 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?

[toc] | [prev] | [next] | [standalone]


#48762

FromArturo B <a7xrturodev@gmail.com>
Date2013-06-19 17:32 -0700
Message-ID<681faf58-e913-41f5-b542-cb5c78983372@googlegroups.com>
In reply to#48753
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%21%20%3A%29

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[i] in correctLetters:
              blanks = blanks[:i] + secretWord[i] + 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 

[toc] | [prev] | [next] | [standalone]


#48764

FromArturo B <a7xrturodev@gmail.com>
Date2013-06-19 18:02 -0700
Message-ID<a0ad440c-ab09-4dfd-be18-1abc6ceaa189@googlegroups.com>
In reply to#48753
Fixed, the problem was in 
HANGMANPICS 

I didn't open the brackets.

Thank you guys :)

[toc] | [prev] | [next] | [standalone]


#48766

FromChris Angelico <rosuav@gmail.com>
Date2013-06-20 11:09 +1000
Message-ID<mailman.3604.1371690571.3114.python-list@python.org>
In reply to#48764
On Thu, Jun 20, 2013 at 11:02 AM, Arturo B <a7xrturodev@gmail.com> wrote:
> 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web