Intermediate Python user needed help

Discussion in 'Python' started by John Mordecai Dildy, Aug 5, 2012.

  1. 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

    Please help me

    Email me at if you have any help for me
     
    John Mordecai Dildy, Aug 5, 2012
    #1
    1. Advertising

  2. John Mordecai Dildy

    John Ladasky Guest

    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 Ladasky, Aug 5, 2012
    #2
    1. Advertising

  3. 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, Aug 5, 2012
    #3
  4. 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 isi know there is things wrong with it but the thing is im fixing a code fora 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
     
    John Mordecai Dildy, Aug 5, 2012
    #4
  5. John Mordecai Dildy

    Andrew Berg Guest

    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
     
    Andrew Berg, Aug 5, 2012
    #5
  6. John Mordecai Dildy

    xDog Walker Guest

    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.
     
    xDog Walker, Aug 5, 2012
    #6
  7. 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, Aug 5, 2012
    #7
  8. 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
     
    John Mordecai Dildy, Aug 5, 2012
    #8
  9. File "ex26.py", line 84
    .print_first_word(sorted_words)
    ^
    SyntaxError: invalid syntax

    is what i have now and i dont see the problem like usual (i only post problems that i cant fix).
     
    John Mordecai Dildy, Aug 5, 2012
    #9
  10. 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
     
    Steven D'Aprano, Aug 5, 2012
    #10
  11. On Sunday, August 5, 2012 4:24:45 PM UTC-4, Steven D'Aprano wrote:
    > 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


    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, Aug 5, 2012
    #11
  12. 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
     
    John Mordecai Dildy, Aug 5, 2012
    #12
  13. John Mordecai Dildy

    Roy Smith Guest

    In article <>,
    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


    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?
     
    Roy Smith, Aug 5, 2012
    #13
  14. John Mordecai Dildy

    Tim Chase Guest

    On 08/05/12 15:52, 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


    "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
     
    Tim Chase, Aug 5, 2012
    #14
  15. 2012/8/5 John Mordecai Dildy <>:
    > 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
    > --
    > 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
     
    Vlastimil Brom, Aug 5, 2012
    #15
  16. John Mordecai Dildy

    Zero Piraeus Guest

    :

    On 5 August 2012 16:52, 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


    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.
     
    Zero Piraeus, Aug 5, 2012
    #16
  17. John Mordecai Dildy

    MRAB Guest

    On 05/08/2012 21:52, 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
    >

    You have "start-point", but I think that should be "start_point",
    judging by the previous line.
     
    MRAB, Aug 5, 2012
    #17
  18. Thanks everyone that has put input into this its working on out error by error

    On Sunday, August 5, 2012 5:03:50 PM UTC-4, Tim Chase wrote:
    > On 08/05/12 15:52, 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

    >
    >
    >
    > "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
     
    John Mordecai Dildy, Aug 5, 2012
    #18
  19. John Mordecai Dildy

    MRAB Guest

    On 05/08/2012 22:03, Tim Chase wrote:
    > On 08/05/12 15:52, 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

    >
    > "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.
     
    MRAB, Aug 5, 2012
    #19
  20. Im using Textwrangler and thats the only text editor that im using just saying for everyone
     
    John Mordecai Dildy, Aug 5, 2012
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ElementX
    Replies:
    9
    Views:
    514
    RedGrittyBrick
    Oct 1, 2008
  2. Learning Python
    Replies:
    1
    Views:
    581
    Chris Rebert
    Feb 24, 2009
  3. wesley chun
    Replies:
    0
    Views:
    251
    wesley chun
    Mar 31, 2010
  4. wesley chun
    Replies:
    0
    Views:
    265
    wesley chun
    Apr 27, 2010
  5. bhabs
    Replies:
    2
    Views:
    412
    Tad J McClellan
    Feb 13, 2008
Loading...

Share This Page