Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Intermediate Python user needed help

Reply
Thread Tools

Intermediate Python user needed help

 
 
John Mordecai Dildy
Guest
Posts: n/a
 
      08-05-2012
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
 
Reply With Quote
 
 
 
 
John Ladasky
Guest
Posts: n/a
 
      08-05-2012
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.
 
Reply With Quote
 
 
 
 
John Mordecai Dildy
Guest
Posts: n/a
 
      08-05-2012
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
 
Reply With Quote
 
John Mordecai Dildy
Guest
Posts: n/a
 
      08-05-2012
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
 
Reply With Quote
 
Andrew Berg
Guest
Posts: n/a
 
      08-05-2012
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
 
Reply With Quote
 
xDog Walker
Guest
Posts: n/a
 
      08-05-2012
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.

 
Reply With Quote
 
John Mordecai Dildy
Guest
Posts: n/a
 
      08-05-2012
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
 
Reply With Quote
 
John Mordecai Dildy
Guest
Posts: n/a
 
      08-05-2012
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
 
Reply With Quote
 
John Mordecai Dildy
Guest
Posts: n/a
 
      08-05-2012
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).
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      08-05-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
intermediate python csv reader/writer question from a beginner Learning Python Python 1 02-24-2009 12:32 AM
Help Help, I am intermediate in Java...need help in follow case ElementX Java 9 10-01-2008 08:02 PM
LWP user agent grabs the intermediate wait page after POST intead ofthe actual result page bhabs Perl Misc 2 02-13-2008 01:55 AM
NEEDED IMMEDIATELY!!! Intermediate Technical Support Specialist Jennifer Nasnas Computer Support 9 06-25-2004 11:09 PM



Advertisments