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 "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
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.)
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
In article <506eb405-eb07-4175-9efb-40475cabacf1@googlegroups.com>,
John Mordecai Dildy <jdild...@gmail.com> 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?
> 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.
2012/8/5 John Mordecai Dildy <jdild...@gmail.com>:
> 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
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.
On 5 August 2012 16:52, John Mordecai Dildy <jdild...@gmail.com> 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?
> 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.
> 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.
> 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.
> 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.
> In article <mailman.2972.1344200565.4697.python-l...@python.org>,
> Tim Chase <python.l...@tim.thechases.com> 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.