Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Intermediate Python user needed help

162 views
Skip to first unread message
Message has been deleted

John Ladasky

unread,
Aug 5, 2012, 3:34:33 PM8/5/12
to
Check line 76 of your code for errors.

If line 76 is incorrectly formed, Python may see line 77 as a continuation of line 76 and throw the SyntaxError because of that.

John Mordecai Dildy

unread,
Aug 5, 2012, 3:44:03 PM8/5/12
to
Well 75 and 76 is a blank line of text but i will see if i can take out those lines to see if it is the problem thanks John

John Mordecai Dildy

unread,
Aug 5, 2012, 3:51:31 PM8/5/12
to
Ive tried to delete the spaces in 75 and 76 to see if it made a change but it has not made a difference to it. Here is the full code and the thing is i know there is things wrong with it but the thing is im fixing a code for a friend to help him getting with the coding:


def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words

def sort_words(words):
"""Sorts the words."""
return sorted(words)

def print_first_word(words):
"""Prints the first word after popping it off."""
word = words.pop(0)
print word

def print_last_word(words):
"""Prints the last word after popping it off."""
word = words.pop(-1)
print word

def sort_sentence(sentence):
"""Takes in a full sentence and returns the sorted words."""
words = break_words(sentence)
return sort_words(words)

def print_first_and_last(sentence):
"""Prints the first and last words of the sentence."""
words = break_words(sentence)
print_first_word(words)
print_last_word(words)

def print_first_and_last_sorted(sentence):
"""Sorts the words then prints the first and last one."""
words = sort_sentence(sentence)
print_first_word(words)
print_last_word(words)


print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'

poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explantion
\n\t\twhere there is none.
"""


print "--------------"
print poem
print "--------------"

five = 10 - 2 + 3 - 5
print "This should be five: %s" % five

def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates


start_point = 10000
beans, jars, crates == secret_formula(start-point)

print "With a starting point of: %d" % start_point
print "We'd have %d jeans, %d jars, and %d crates." % (beans, jars, crates)

start_point = start_point / 10

print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_pont
sentence = "All good things come to those who wait."

words = ex25.break_words(sentence)
sorted_words = ex25.sort_words(words)

print_first_word(words)
print_last_word(words)
.print_first_word(sorted_words)
print_last_word(sorted_words)
sorted_words = ex25.sort_sentence(sentence)
prin sorted_words

print_irst_and_last(sentence)

print_first_a_last_sorted(senence)


Thank you in advance to anyone that can help me with this code

Andrew Berg

unread,
Aug 5, 2012, 4:09:51 PM8/5/12
to comp.lang.python
On 8/5/2012 2:51 PM, John Mordecai Dildy wrote:
> print "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_pont
> sentence = "All good things come to those who wait."
You are missing a parenthesis at the end of the previous line.

> .print_first_word(sorted_words)
That dot will make this line raise an error.

You should use an IDE or something to highlight syntax errors.
--
CPython 3.3.0b1 | Windows NT 6.1.7601.17803

xDog Walker

unread,
Aug 5, 2012, 4:15:10 PM8/5/12
to pytho...@python.org
On Sunday 2012 August 05 12:51, John Mordecai Dildy wrote:
> print "We'd have %d beans, %d jars, and %d crabapples." %
> secret_formula(start_pont

Add a ) to the end of the line quoted above.

--
Yonder nor sorghum stenches shut ladle gulls stopper torque wet
strainers.

John Mordecai Dildy

unread,
Aug 5, 2012, 4:16:13 PM8/5/12
to
well that work on mac though?
im asking because i see the Windows NT at the bottom of your reply and plus im using 2.6 python not 3.3

John Mordecai Dildy

unread,
Aug 5, 2012, 4:17:45 PM8/5/12
to
On Sunday, August 5, 2012 4:16:13 PM UTC-4, John Mordecai Dildy wrote:
> well that work on mac though?
>
> im asking because i see the Windows NT at the bottom of your reply and plus im using 2.6 python not 3.3

i see the ) problem i have it fixed
Message has been deleted

Steven D'Aprano

unread,
Aug 5, 2012, 4:24:45 PM8/5/12
to
On Sun, 05 Aug 2012 12:51:31 -0700, John Mordecai Dildy wrote:

> Ive tried to delete the spaces in 75 and 76 to see if it made a change
> but it has not made a difference to it.

What made you think that the problem could be fixed by deleting *spaces*?

In general, making random changes to code in the hope that syntax errors
will just go away is not the right way to fix broken code. Even if you
succeed, since you don't know what you did to fix it, how do you know
that your next change won't break it again?

Almost always, when you have a mysterious syntax error on a line that
appears to be perfectly fine, the reason is a missing bracket of some
sort on a previous line. (For Americans, I mean parentheses, brackets or
braces; for Britons and Australians, round square or curly brackets; for
everyone else, whatever you call them.)


--
Steven

John Mordecai Dildy

unread,
Aug 5, 2012, 4:31:18 PM8/5/12
to
Well i have put the spaces back into the code after i did that and had no hope it worked though.

thank you steven for giving me some input

John Mordecai Dildy

unread,
Aug 5, 2012, 4:52:35 PM8/5/12
to
Current Problem at the moment

Traceback (most recent call last):
File "ex26.py", line 66, in <module>
beans, jars, crates = secret_formula(start-point)
NameError: name 'start' is not defined

anyone know how to make start defined

Roy Smith

unread,
Aug 5, 2012, 5:01:20 PM8/5/12
to
In article <506eb405-eb07-4175...@googlegroups.com>,
You gotta give us more to go on than that. Adding a line:

start = 0

right before line 66 will make it defined, but it's almost certainly not
what you want. Give us a little context. What value did you expect
start would have?

Tim Chase

unread,
Aug 5, 2012, 5:03:50 PM8/5/12
to John Mordecai Dildy, pytho...@python.org
"start-point" is not a valid identifier as the "-" isn't permitted
in a variable name. This is the case for just about every language
out there. HTML/XML & CSS are the only languages that come to my
mind in which the dash is considered a valid part of an identifier.

You either mean something like "start_point" (with an underscore
instead of a minus), or you're performing a subtraction of "start
minus point", in which case you'd have to assign those values before
you use them.

-tkc



Vlastimil Brom

unread,
Aug 5, 2012, 5:06:49 PM8/5/12
to John Mordecai Dildy, pytho...@python.org
2012/8/5 John Mordecai Dildy <jdil...@gmail.com>:
> --
> http://mail.python.org/mailman/listinfo/python-list

Hi,
you would need to assign something to the name "start", e.g.
start = 3
the next error would probably be undefined "point", which should get
subtracted from "start" according to the code ...

However, in your case, this is likely another typo in the code,
you probably want "start_point", which is defined in the script already.

hth,
vbr

Zero Piraeus

unread,
Aug 5, 2012, 5:07:43 PM8/5/12
to John Mordecai Dildy, pytho...@python.org
:
I think you could help yourself by reading a good tutorial or two ...
so far, the problems you've raised suggest quite strongly that you
either aren't reading the code with anything like the care that you
need to, or just don't understand Python at all.

Hint: if the offending line were written like this, would it be more
obvious what's wrong?

beans, jars, crates = secret_formula(start - point)

-[]z.

MRAB

unread,
Aug 5, 2012, 5:08:39 PM8/5/12
to pytho...@python.org
You have "start-point", but I think that should be "start_point",
judging by the previous line.

John Mordecai Dildy

unread,
Aug 5, 2012, 5:09:38 PM8/5/12
to
Thanks everyone that has put input into this its working on out error by error

MRAB

unread,
Aug 5, 2012, 5:12:52 PM8/5/12
to pytho...@python.org
On 05/08/2012 22:03, Tim Chase wrote:
> On 08/05/12 15:52, John Mordecai Dildy wrote:
> "start-point" is not a valid identifier as the "-" isn't permitted
> in a variable name. This is the case for just about every language
> out there. HTML/XML & CSS are the only languages that come to my
> mind in which the dash is considered a valid part of an identifier.
>
I believe that Cobol allows "-" in names.

John Mordecai Dildy

unread,
Aug 5, 2012, 5:14:09 PM8/5/12
to comp.lan...@googlegroups.com, pytho...@python.org
Im using Textwrangler and thats the only text editor that im using just saying for everyone

John Mordecai Dildy

unread,
Aug 5, 2012, 5:14:09 PM8/5/12
to pytho...@python.org

Andre Ramaciotti

unread,
Aug 5, 2012, 5:22:12 PM8/5/12
to pytho...@python.org
On 08/05/2012 06:12 PM, MRAB wrote:
> On 05/08/2012 22:03, Tim Chase wrote:
>> On 08/05/12 15:52, John Mordecai Dildy wrote:
>> "start-point" is not a valid identifier as the "-" isn't permitted
>> in a variable name. This is the case for just about every language
>> out there. HTML/XML & CSS are the only languages that come to my
>> mind in which the dash is considered a valid part of an identifier.
>>
> I believe that Cobol allows "-" in names.
>
Lisp certainly does.

Roy Smith

unread,
Aug 5, 2012, 5:32:26 PM8/5/12
to
In article <mailman.2972.1344200...@python.org>,
Or he meant to pass an optional parameter:

beans, jars, crates = secret_formula(start=point)

or an element access:

beans, jars, crates = secret_formula(start.point)

or a bunch of other possibilities.

John Mordecai Dildy

unread,
Aug 5, 2012, 6:00:47 PM8/5/12
to comp.lan...@googlegroups.com, pytho...@python.org
since when did we start talking about lisp?

John Mordecai Dildy

unread,
Aug 5, 2012, 6:00:47 PM8/5/12
to pytho...@python.org

Mark Lawrence

unread,
Aug 5, 2012, 6:15:42 PM8/5/12
to pytho...@python.org
Like it, marks out of 10, 15 :)

--
Cheers.

Mark Lawrence.

Mark Lawrence

unread,
Aug 5, 2012, 6:17:10 PM8/5/12
to pytho...@python.org
On 05/08/2012 23:00, John Mordecai Dildy wrote:
> since when did we start talking about lisp?
>

Just about anything is on topic here.

--
Cheers.

Mark Lawrence.

John Mordecai Dildy

unread,
Aug 5, 2012, 6:39:31 PM8/5/12
to
oh

Tim Chase

unread,
Aug 5, 2012, 7:19:55 PM8/5/12
to John Mordecai Dildy, pytho...@python.org
On 08/05/12 17:00, John Mordecai Dildy wrote:
> since when did we start talking about lisp?

Though not a lisper, the Python tie-in was my reply: Python (among
many other languages) doesn't allow a "-" as a character in
identifiers as you appeared to use it in your code. Unlike HTML,
XML, CSS, and apparently lisp and COBOL (thanks, MRAB, for ripping
open that scab after years of trying to repress those COBOL memories
:-) where identifiers may contain the dash.

-tkc


Tim Chase

unread,
Aug 5, 2012, 7:27:47 PM8/5/12
to Roy Smith, pytho...@python.org
On 08/05/12 16:32, Roy Smith wrote:
> Tim Chase <pytho...@tim.thechases.com> wrote:
>> You either mean something like "start_point" (with an underscore
>> instead of a minus), or you're performing a subtraction of "start
>> minus point", in which case you'd have to assign those values before
>> you use them.
>
> Or he meant to pass an optional parameter:
>
> beans, jars, crates = secret_formula(start=point)
>
> or an element access:
>
> beans, jars, crates = secret_formula(start.point)

Or pass a boolean

beans, jars, crates = secret_formula(start>point)

Or subscript with an also-missing close-bracket

beans, jars, crates = secret_formula(start[point])

Or call a function with an also-missing close-paren

beans, jars, crates = secret_formula(start(point))

Or it was just a finger-flub

beans, jars, crates = secret_formula(startpoint)

:-)

-tkc


Roy Smith

unread,
Aug 5, 2012, 7:32:26 PM8/5/12
to
In article <mailman.2984.1344208...@python.org>,
Does BNF count as a language?

William R. Wing

unread,
Aug 5, 2012, 7:38:58 PM8/5/12
to John Mordecai Dildy, pytho...@python.org, William R. Wing (Bill Wing)
On Aug 5, 2012, at 5:14 PM, John Mordecai Dildy <jdil...@gmail.com> wrote:

> Im using Textwrangler and thats the only text editor that im using just saying for everyone
> --
> http://mail.python.org/mailman/listinfo/python-list

(With apologies, I initially sent this privately to John, and not to the list.)

As I'm sure you are aware, TextWrangler is the free baby brother of BBEdit which, although not free, contains automatic syntax highlighting for exactly the sort of error you made. It would have signaled "unmatched parentheses" the instant you finished inputting that line in your original bit of code. If you value your time, I think you will find it more than pays for itself.

Just saying…
-Bill

Steven D'Aprano

unread,
Aug 5, 2012, 8:42:40 PM8/5/12
to
And Forth.

Generally speaking, concatenative languages like Forth can use any
symbols they wish in identifiers, apart from the token separator (usually
whitespace), since they don't have syntax as we know it in more
traditional languages.

E.g. in Forth : is the word (command) to start defining a new word, but
this does not stop you from defining a word called ::: or "foo:bar" (with
or without the quotes!).



--
Steven
Message has been deleted

Tim Chase

unread,
Aug 5, 2012, 9:27:07 PM8/5/12
to Dennis Lee Bieber, pytho...@python.org
On 08/05/12 20:15, Dennis Lee Bieber wrote:
> On Sun, 05 Aug 2012 19:32:26 -0400, Roy Smith <r...@panix.com> declaimed
>>> Though not a lisper, the Python tie-in was my reply: Python (among
>>> many other languages) doesn't allow a "-" as a character in
>>> identifiers as you appeared to use it in your code. Unlike HTML,
>>> XML, CSS, and apparently lisp and COBOL (thanks, MRAB, for ripping
>>> open that scab after years of trying to repress those COBOL memories
>>> :-) where identifiers may contain the dash.
>>
>> Does BNF count as a language?
>
> It's a meta-language <G>

I see what you did there, using a dash in your identifier...

-tkc




alex23

unread,
Aug 5, 2012, 10:49:38 PM8/5/12
to
On Aug 6, 7:14 am, John Mordecai Dildy <jdild...@gmail.com> wrote:
> Im using Textwrangler and thats the only text editor that im using just saying for everyone

Why bother using an actual development tool when you can get an entire
mailing list to be your syntax checker, right?

Ethan Furman

unread,
Aug 6, 2012, 12:05:50 PM8/6/12
to John Mordecai Dildy, pytho...@python.org
John Mordecai Dildy wrote:
> I am currently using python 2.6 and am not going to install the newer versions of python and i am looking for people that are still using ver 2.6 in python to help with with the code line:
>
> sentence = "All good things come to those who wait."
>
> then im getting this error message when i dont see the problem with it:
>
> File "ex26.py", line 77
> sentence = "All good things come to those who wait."
> ^
> SyntaxError: invalid syntax

John Mordecai Dildy wrote:
> Current Problem at the moment
>
> Traceback (most recent call last):
> File "ex26.py", line 66, in <module>
> beans, jars, crates = secret_formula(start-point)
> NameError: name 'start' is not defined
>
> anyone know how to make start defined

In your subject line you state that you are an intermediate Python user.
These are not the errors an intermediate user would make, nor the
questions an intermediate user would ask. These are the errors that
somebody who doesn't know Python would make.

Please do not misrepresent yourself.

~Ethan~

P.S. The scale I am accustomed to is Novice -> Intermediate -> Advanced
-> Master

Are there scales out there that would put these types of questions in
the "intermediate" category?

Alec Taylor

unread,
Aug 6, 2012, 12:13:54 PM8/6/12
to Ethan Furman, John Mordecai Dildy, pytho...@python.org
On Tue, Aug 7, 2012 at 2:05 AM, Ethan Furman <et...@stoneleaf.us> wrote:
> John Mordecai Dildy wrote:
>>
>> I am currently using python 2.6 and am not going to install the newer
>> versions of python and i am looking for people that are still using ver 2.6
>> in python to help with with the code line:
>>
>> sentence = "All good things come to those who wait."
>>
>> then im getting this error message when i dont see the problem with it:
>>
>> File "ex26.py", line 77
>> sentence = "All good things come to those who wait."
>> ^
>> SyntaxError: invalid syntax
>
>
> John Mordecai Dildy wrote:
>> Current Problem at the moment
>>
>> Traceback (most recent call last):
>> File "ex26.py", line 66, in <module>
>> beans, jars, crates = secret_formula(start-point)
>> NameError: name 'start' is not defined
>>
>> anyone know how to make start defined
>
> In your subject line you state that you are an intermediate Python user.
> These are not the errors an intermediate user would make, nor the questions
> an intermediate user would ask. These are the errors that somebody who
> doesn't know Python would make.
>
> Please do not misrepresent yourself.
+1

>
> ~Ethan~
>
> P.S. The scale I am accustomed to is Novice -> Intermediate -> Advanced ->
> Master

What, no n00b before Novice?

:P

>
> Are there scales out there that would put these types of questions in the
> "intermediate" category?
> --
> http://mail.python.org/mailman/listinfo/python-list

Jean-Michel Pichavant

unread,
Aug 6, 2012, 1:05:17 PM8/6/12
to pytho...@python.org
Ethan Furman wrote:
>
> ~Ethan~
>
> P.S. The scale I am accustomed to is Novice -> Intermediate ->
> Advanced -> Master
>
> Are there scales out there that would put these types of questions in
> the "intermediate" category?
Troll -> Novice -> Intermediate -> Advanced

Trolls are quite specific, they're able to spread over all upper
levels, in disguise.

:o)

JM
Message has been deleted

Chris Angelico

unread,
Aug 6, 2012, 5:59:44 PM8/6/12
to pytho...@python.org
On Tue, Aug 7, 2012 at 5:22 AM, Dennis Lee Bieber <wlf...@ix.netcom.com> wrote:
> So am I beginner, intermediate, advanced, expert?

I wonder would this sort of a scale help:

http://www.geekcode.com/geek.html#perl

Novice: P
Intermediate: P+ or P++
Advanced: P+++
Master: P++++

ChrisA

Steven D'Aprano

unread,
Aug 6, 2012, 9:16:21 PM8/6/12
to
On Mon, 06 Aug 2012 09:05:50 -0700, Ethan Furman wrote:

> These are not the errors an intermediate user would make, nor the
> questions an intermediate user would ask. These are the errors that
> somebody who doesn't know Python would make.

> P.S. The scale I am accustomed to is Novice -> Intermediate -> Advanced
> -> Master
>
> Are there scales out there that would put these types of questions in
> the "intermediate" category?

http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect


Or to put it another way:

http://www.quickmeme.com/meme/359ofp/
http://www.quickmeme.com/meme/3q8648/




--
Steven

Jugurtha Hadjar

unread,
Aug 6, 2012, 11:06:03 PM8/6/12
to pytho...@python.org
On 08/05/2012 09:52 PM, John Mordecai Dildy wrote:
> NameError: name 'start' is not defined
>
> anyone know how to make start defined

Maybe rename it "defined_start" ;)

I wonder how someone can get to the point of writing more than 76 lines
of code while not only still making this kind of errors, but not even
knowing what these errors mean and how to correct them. It's impossible.
You can't write programs that are more than 10 lines without having
encountered these errors and learnt how to deal with them.

Unless you're reading exercises from a book, and feeling that you're
"intermediate", you started reading from chapter 28 in a 29 chapters book.



--
~Jugurtha Hadjar,

Message has been deleted

rusi

unread,
Aug 6, 2012, 11:55:02 PM8/6/12
to
On Aug 7, 6:16 am, Steven D'Aprano <steve
+comp.lang.pyt...@pearwood.info> wrote:
> On Mon, 06 Aug 2012 09:05:50 -0700, Ethan Furman wrote:
> >   These are not the errors an intermediate user would make, nor the
> > questions an intermediate user would ask.  These are the errors that
> > somebody who doesn't know Python would make.
> > P.S.  The scale I am accustomed to is Novice -> Intermediate -> Advanced
> > -> Master
>
> > Are there scales out there that would put these types of questions in
> > the "intermediate" category?
>
> http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect

Thanks for that link -- I'd been looking for it.

rusi

unread,
Aug 6, 2012, 11:52:42 PM8/6/12
to
If you've ever taught programming in a formal teaching setup, you
would not be surprised when students submit C 'projects' that wont
even compile (leave aside segfault).

On a more personal note, the first program I wrote was in Cobol. I
got only 350 errors before the compiler copped out. It was a bit
traumatic. Later on I found I forgot to write
PROCEDURE DIVISION.

So its good to remember how spoilt we are on python that we can test
out 10 lines at a time.

John Mordecai Dildy

unread,
Aug 7, 2012, 10:09:37 AM8/7/12
to comp.lan...@googlegroups.com, pytho...@python.org
On Monday, August 6, 2012 11:39:45 PM UTC-4, Dennis Lee Bieber wrote:
> On Tue, 7 Aug 2012 07:59:44 +1000, Chris Angelico <ros...@gmail.com>
>
> declaimed the following in gmane.comp.python.general:
> Surely we can rise above mere "pluses" and rank using "stars" (*) --
>
> a four-star Pythoneer (or whatever the preferred term is)?
>
>
>
> --
>
> Wulfraed Dennis Lee Bieber AF6VN
>
> wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

No matter what level you are in python you will still make mistakes every once in a while but if your like a expert you just notice it faster

John Mordecai Dildy

unread,
Aug 7, 2012, 10:09:37 AM8/7/12
to pytho...@python.org
Message has been deleted
0 new messages