Re: [Tutor] SyntaxError Message

2014-07-08 Thread Danny Yoo
 I have no programming experience and am trying to  teaching myself python.
 Am trying to replicate the code below but I get the error message below
 highlighted in yellow:


We need a little more information.  Where does this code come from?
What text book or instructional material are you using?


I ask because the code you're doing is unusual looking, and appears to
be out-of-context.  To be more specific, the following part of your
program:

return input (1)

doesn't make too much sense in isolation.

The errors you're seeing are due to the fish-out-of-waterness of the
code: the return statement only makes sense if you're writing a
function definition, but if you're just getting started, you probably
haven't learned about how to write function definitions yet.

If you can point us to the instructional material you're looking at,
we might give better suggestions as to what's missing.

But alternatively, have you tried the following tutorial instead?

http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_3

It may be a gentler introduction to the language than what you're
looking at now.


Good luck!  If you have more questions, please feel free to ask.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SyntaxError Message

2014-07-08 Thread Danny Yoo
Following up.  I can guess that you're looking at:

http://www.sthurlow.com/python/lesson05/

But I would like not to guess unless I have no choice. In the future,
if you're asking for help, provide context.  The reason why it's very
useful to say where you're learning from is because we can then look
at previous things you have seen before, and try to relate those past
things with what you're doing now.

In this case, now that I know the context more, I can look at the
material myself and see if it makes sense.  Sometimes tutorials can be
confusingly written.

Ah.  In particular, the Code Example 9 in the link above is not
presented well.  I say this because it is not even a complete program!
 And yet the author is notating it as if it were a complete program by
putting it in its own figure.  If you tried to do Code Example 9, it
would raise the exact same error messages you're seeing now.

Hmm... I have other reservations about this tutorial.  It's presumably
trying to teach functions, but it is not really using the functions as
things that return useful values.  add(), sub(), mul(), and div() in
Code Example 14 are not great examples of functions.


I think you may want to switch to a different tutorial and see if it
is easier to approach.  Since you're using Python 2, I have to
backtrack on the tutorial I linked in a previous message: I needed to
have referred to a tutorial that used Python 2, not Python 3.  My
apologies!

Here is a link to a good tutorial:
http://openbookproject.net/thinkcs/python/english2e/

Please try that one instead and see if it makes more sense.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SyntaxError Message

2014-07-08 Thread Dave Angel
Pamela Wightley pamela.wight...@morgij.com.au Wrote in message:
 
 

This is a text mailing list.  So leaving an html message blocks
 some of us from seeing what you intended.  Color and other
 formatting vanishes for many.  Please tell your email program to
 post in text mode.

The problem with your fragment is that the return statement only
 makes sense inside a function,  but you don't begin with a def
 statement. 

-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SyntaxError Message

2014-07-08 Thread Alan Gauld

On 08/07/14 02:41, Pamela Wightley wrote:

Hi All,

I have no programming experience and am trying to  teaching myself
python. Am trying to replicate the code below but I get the error
message below highlighted in yellow:


Unfortunately I can't see anything in yellow, probably due to enmail 
losing the formatting.


But the code below has several errors and looks like its part
of a bigger program. It also looks completely unrelated to the
errors you show us further down.



choice = input(Choose your option: )


You seem to be using Python 2 in which case using input() is
frowned upon. Its better to use raw_input() and convert the
resultant string to a number using int() or float() as needed.
[ In Python 3 input() has been rwe oved and raw_input renamed to input()...]



 if choice == 1:


indentation(spacing) is very importanbt in Python.
You should only indent the code inside a code block that follows a 
structural statement such as if/for/while/def/class etc.


Indenting the if statement after the input() will raise an error.


 add1 = input(Add this: )



But this should e indented because its part of the if block.



 add2 = input(to this: )

 print add1, +, add2, =, add1 + add2

 elif choice == 2:

 sub2 = input(Subtract this: )

 sub1 = input(from this: )

 print sub1, -, sub2, =, sub1 - sub2

 elif choice == 3:

 mul1 = input(Multiply this: )

 mul2 = input(with this: )

 print mul1, *, mul2, =, mul1 * mul2

 elif choice == 4:

 div1 = input(Divide this: )

 div2 = input(by this: )

 print div1, /, div2, =, div1 / div2

 elif choice == 5:

 loop = 0

Any assistance appreciated.

ERROR MESSAGE


return input (1)


   File stdin, line 1

SyntaxError: 'return' outside function



This seems completely unrelated to the choice code?
You can only use return inside a function (ie a block
starting def)


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor