Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-05 Thread Alan Gauld via Tutor
On 05/02/17 01:29, boB Stepp wrote:

> But it seems to me on further thought that both REPL and what seems
> most consistent to me, "...wait until all the input has been read,
> then evaluate it all..." amounts to the same thing in the case of
> entering function definitions into the interpreter.  

Nope, the function definition is a single executable statement.
def is a command just like print. The command is to compile the
block of code and store it as a function object that can later
be called. So the interpreter is being completely consistent
in looking for the full definition in that case.

You are right that the interactive interpreter *could* have read
all input before executing it, but by design it doesn't. It is
an arbitrary choice to make the interpreter act on a single
input statement at a time (and personally I think a good one).

The problem with executing multiple statements at a time is
that your mistakes are often not where you think they are.
And by showing you the output of every statement as you go
you notice the error as it happens and don't mistakenly make
assumptions about which of the previous N statements
contains the bug. So personally I prefer the Python style
interpreter. Perl by contrast is more like your preference
and interprets to an EOF and I find that too easy to make
mistakes.

Best of all I guess is Smalltalk which executes any code
you highlight with a mouse...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread boB Stepp
I'm beginning to believe I am being incredibly dense today ...

On Sat, Feb 4, 2017 at 6:16 PM, Ben Finney  wrote:
> boB Stepp  writes:
>
>> But would it not be more consistent to assume the user knows what he
>> is doing based on the new (lack of) indentation being used, accept
>> that a new section of code outside of the for loop is being typed in,
>> and wait for the blank line before executing everything typed in?
>
> That's not the purpose of the REPL. It is to Read (one statement),
> Evaluate the statement, Print the result, and Loop.
>
> You're wanting a different behaviour: wait until all the input has been
> read, then evaluate it all.

Ben, I read your answer, did some Googling on REPL, seemed satisfied,
and consigned this thread of emails to the trash bin, believing it was
all settled in my mind.  But then I got to wondering again ...

As already mentioned the interactive interpreter handles multiline
statements.  In the case of defining a function, the interpreter
allows quite complex, nested code to be entered, only ending the input
of code process when that blank line occurs in proper context.  By
this I mean that quotes have been properly closed, all parens matched,
etc.

But it seems to me on further thought that both REPL and what seems
most consistent to me, "...wait until all the input has been read,
then evaluate it all..." amounts to the same thing in the case of
entering function definitions into the interpreter.  The interpreter
cannot know that the user has finished inputting code until it
encounters that finalizing blank line.  After all I can have in my
function many for loops followed by unindented print functions in
seeming as much complexity as I can bear to type in accurately.  This
is giving exactly the consistent behavior that I would expect.  But if
instead of starting with a for loop inside a function with following
unindented other statements I instead start with *exactly the same
sequence of statements* but without "def ...:", then I get a syntax
error.  I am not trying to be deliberately argumentative, but I do not
see why the two cases are treated differently when the entered code is
exactly the same between the two with the sole exception of one has an
enclosing function definition line the other code does not.  I am
continuing to scratch my evermore balding head on this one!  But it is
not a big deal, and I do not want to blow things out of proportion.

More practically, I wonder if it is all as simple as not having to hit
the enter key twice for true one-liner statements.  Such lines can
truly be handled one line at a time per REPL.  If I had things "my
way", then that would make the more common situation of true
one-line-at-a-time read-evaluate-print-loop more cumbersome.

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


Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread Ben Finney
boB Stepp  writes:

> But would it not be more consistent to assume the user knows what he
> is doing based on the new (lack of) indentation being used, accept
> that a new section of code outside of the for loop is being typed in,
> and wait for the blank line before executing everything typed in?

That's not the purpose of the REPL. It is to Read (one statement),
Evaluate the statement, Print the result, and Loop.

You're wanting a different behaviour: wait until all the input has been
read, then evaluate it all.

If that's what you want: just write it all into a text file, and execute
that.

-- 
 \ “Nature is trying very hard to make us succeed, but nature does |
  `\   not depend on us. We are not the only experiment.” —Richard |
_o__)   Buckminster Fuller, 1978-04-30 |
Ben Finney

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


Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread boB Stepp
On Sat, Feb 4, 2017 at 5:44 PM, Alan Gauld via Tutor  wrote:
> On 04/02/17 22:56, boB Stepp wrote:
>> On Sat, Feb 4, 2017 at 4:40 PM, David  wrote:
>>> On 5 February 2017 at 09:02, boB Stepp  wrote:
 py3: a
 ['Mary', 'had', 'a', 'little', 'lamb', 'break']
 py3: for w in a:
 ... print(w)
 ... print('Huh?')
   File "", line 3
 print('Huh?')
 ^
 SyntaxError: invalid syntax

 I don't understand why this throws a SyntaxError.  If I wrap
 essentially the same code into a function it works:
>
> Because you never completed the for loop. The interactive
> interpreter tries to exercise each Python statement as it
> goes but it cannot exercise the loop until it sees the end
> of the block. Your second print statement is outside the
> block but the block has not yet been executed so it sees
> an error.

But would it not be more consistent to assume the user knows what he
is doing based on the new (lack of) indentation being used, accept
that a new section of code outside of the for loop is being typed in,
and wait for the blank line before executing everything typed in?

>
> Alternatively if you put your code inside a function
> definition it will understand it because it interprets
> the full definition. Then when you call the function
> it executes it as a whole. There is no discrepency in
> what the interpreter is trying to interpret. But when
> you do it at the top level  the interpreter is still
> waiting for the end of the loop.

Again, the interpreter is waiting for that blank line before deciding
the function definition is complete.  Why cannot this be the key
criteria for the for loop with additional code being added, wait for
the blank line to be entered, and then execute the whole shebang?  To
me, this seems to be more consistent behavior.

> Does that help?

It confirms what I was concluding.  This is what happens when I have
some extra time on my hand, decide to carefully scrutinize the
official Python 3 tutorial, and then think, wonder and play around in
the interpreter.  ~(:>))


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


Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread Alan Gauld via Tutor
On 04/02/17 22:56, boB Stepp wrote:
> On Sat, Feb 4, 2017 at 4:40 PM, David  wrote:
>> On 5 February 2017 at 09:02, boB Stepp  wrote:
>>> py3: a
>>> ['Mary', 'had', 'a', 'little', 'lamb', 'break']
>>> py3: for w in a:
>>> ... print(w)
>>> ... print('Huh?')
>>>   File "", line 3
>>> print('Huh?')
>>> ^
>>> SyntaxError: invalid syntax
>>>
>>> I don't understand why this throws a SyntaxError.  If I wrap
>>> essentially the same code into a function it works:

Because you never completed the for loop. The interactive
interpreter tries to exercise each Python statement as it
goes but it cannot exercise the loop until it sees the end
of the block. Your second print statement is outside the
block but the block has not yet been executed so it sees
an error.

If you put a blank line it will work OK.

Alternatively if you put your code inside a function
definition it will understand it because it interprets
the full definition. Then when you call the function
it executes it as a whole. There is no discrepency in
what the interpreter is trying to interpret. But when
you do it at the top level  the interpreter is still
waiting for the end of the loop.

Does that help?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread David
On 5 February 2017 at 09:56, boB Stepp  wrote:
> On Sat, Feb 4, 2017 at 4:40 PM, David  wrote:
>>>
>>> I don't understand why this throws a SyntaxError.  If I wrap
>>> essentially the same code into a function it works:
>>
>> From [1]: "When a compound statement is entered interactively, it must
>> be followed by a blank line to indicate completion (since the parser
>> cannot guess when you have typed the last line). Note that each line
>> within a basic block must be indented by the same amount."
>>
>> Does that help?
>
> Not really.  I do not understand why I can define a function in the
> interactive interpreter and nest (apparently) any number of for loops,
> if-elif-else constructs, etc., and as long as I get the indentation of
> each block correct, it will accept it.  But apparently if I start off
> with something which is by definition multiline like typing in a for
> loop, I cannot continue the multiline statements with something
> outside the for loop even if the indentation indicates that the
> following statement is not part of the for loop above.  I can accept
> this, but I do not understand why this can't be parsed correctly by
> the interpreter solely based on the indentation and lack of
> indentation being used.

I am guessing it is because the interpreter implements only single
level of auto-indent, for every top-level compound statement, and it
requires that to be terminated with one blank line.

It appears that all extra indenting must be done manually.

I could be wrong, as I would not work this way. Instead I would use an
editor to create the function, and then import it to create the desired
initial state which could then be explored interactively.

I just tried to give you a quick response. Maybe someone else will
give you a more authoritative answer, if there is one.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread boB Stepp
On Sat, Feb 4, 2017 at 4:40 PM, David  wrote:
> On 5 February 2017 at 09:02, boB Stepp  wrote:
>> py3: a
>> ['Mary', 'had', 'a', 'little', 'lamb', 'break']
>> py3: for w in a:
>> ... print(w)
>> ... print('Huh?')
>>   File "", line 3
>> print('Huh?')
>> ^
>> SyntaxError: invalid syntax
>>
>> I don't understand why this throws a SyntaxError.  If I wrap
>> essentially the same code into a function it works:
>
> From [1]: "When a compound statement is entered interactively, it must
> be followed by a blank line to indicate completion (since the parser
> cannot guess when you have typed the last line). Note that each line
> within a basic block must be indented by the same amount."
>
> Does that help?

Not really.  I do not understand why I can define a function in the
interactive interpreter and nest (apparently) any number of for loops,
if-elif-else constructs, etc., and as long as I get the indentation of
each block correct, it will accept it.  But apparently if I start off
with something which is by definition multiline like typing in a for
loop, I cannot continue the multiline statements with something
outside the for loop even if the indentation indicates that the
following statement is not part of the for loop above.  I can accept
this, but I do not understand why this can't be parsed correctly by
the interpreter solely based on the indentation and lack of
indentation being used.

C'est la vie Python!



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


Re: [Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread David
On 5 February 2017 at 09:02, boB Stepp  wrote:
> py3: a
> ['Mary', 'had', 'a', 'little', 'lamb', 'break']
> py3: for w in a:
> ... print(w)
> ... print('Huh?')
>   File "", line 3
> print('Huh?')
> ^
> SyntaxError: invalid syntax
>
> I don't understand why this throws a SyntaxError.  If I wrap
> essentially the same code into a function it works:

>From [1]: "When a compound statement is entered interactively, it must
be followed by a blank line to indicate completion (since the parser
cannot guess when you have typed the last line). Note that each line
within a basic block must be indented by the same amount."

Does that help?

[1] https://docs.python.org/3/tutorial/introduction.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Syntax error while attempting to type in multiline statements in the interactive interpreter

2017-02-04 Thread boB Stepp
py3: a
['Mary', 'had', 'a', 'little', 'lamb', 'break']
py3: for w in a:
... print(w)
... print('Huh?')
  File "", line 3
print('Huh?')
^
SyntaxError: invalid syntax

I don't understand why this throws a SyntaxError.  If I wrap
essentially the same code into a function it works:

py3: def print_list(a_list):
... for item in a_list:
... print(item)
... print('Huh?')
...
py3: print_list(a)
Mary
had
a
little
lamb
break

What am I not understanding here?

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


Re: [Tutor] syntax error help

2016-08-26 Thread Alan Gauld via Tutor
On 30/03/16 19:05, Awais Mamoon wrote:
> Hi my code should be working however keeps coming up with invalid syntax but
> I know there isn’t one. 

You are wrong. There is.
I suspect the error message tells you where it is.
In future please include the full error message with your code.

Look closely at this function:

> def EncryptionOrDecryption(plaintext_message, Keyword):
> 
>  NewLetter = ("")
>  Ciphertext = ("")
>  PositionKeyword = 0
>  print('Do you wish to encrypt or decrypt')
>  option = input()
> 
>  if option == "e" or "encrypt":
>   for i in plaintext_message:
>if i == "":
> Ciphertext = Ciphertext + ""
>else:
> NewLetter = (alphabet.index(i)+1) +
> alphabet.index(Keyword[PositionKeyword]
> PositionKeyword = PositionKeyword + 1
> if PositionKeyword == len(Keyword):
>  PositionKeyword = 0
> if NewLetter > 25:
> NewLetter = NewLetter - 26
>Ciphertext = Ciphertext + alphabet[NewLetter]
>  return Ciphertext
> 
>  elif option == "d" or "decrypt":
>for i in plaintext_message:
>if i == "":
> Ciphertext = Ciphertext + ""
>else:
> NewLetter = (alphabet.index(i)-1) +
> alphabet.index(Keyword[PositionKeyword])
> PositionKeyword = Keyword + 1
> if PositionKeyword == len(Keyword):
>  PositionKeyword = 0
> if NewLetter > 25:
>  NewLetter = NewLetter - 26
>Ciphertext = Ciphertext + alphabet[NewLetter]
>  return Ciphertext


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] syntax error help

2016-08-26 Thread David Rock

> On Mar 30, 2016, at 13:05, Awais Mamoon  wrote:
> 
> Hi my code should be working however keeps coming up with invalid syntax but
> I know there isn’t one. Please help me its been 2 hours
> 

When you run your code, what is the actual error you get (copy and paste the 
entire thing, please)?  Where does it say the syntax error is?

— 
David Rock
da...@graniteweb.com




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


[Tutor] syntax error help

2016-08-26 Thread Awais Mamoon
Hi my code should be working however keeps coming up with invalid syntax but
I know there isn’t one. Please help me its been 2 hours

Here is my code:

alphabet = 'abcdefghijklmnaopqrstuvwxyz'

 

#gets the message from the user so it can Encrypt or Decrypt

def getMessage():

 print('Enter your message:')

 return input()



#gets the key from the use so it can Encrypt or Decrypt the chosen message

def getKey():

while True:

print("please enter your keyword")

Keyword = input()

valid_Keyword = True

for letter in Keyword:

if (letter not in alphabet) and (letter != " "):

valid_Keyword = False

if valid_Keyword == False:

print("you need to enter a valid keyword")

if valid_Keyword == True:

return Keyword

 

def EncryptionOrDecryption(plaintext_message, Keyword):

 NewLetter = ("")

 Ciphertext = ("")

 PositionKeyword = 0

 print('Do you wish to encrypt or decrypt')

 option = input()

 if option == "e" or "encrypt":

  for i in plaintext_message:

   if i == "":

Ciphertext = Ciphertext + ""

   else:

NewLetter = (alphabet.index(i)+1) +
alphabet.index(Keyword[PositionKeyword]

PositionKeyword = PositionKeyword + 1

if PositionKeyword == len(Keyword):

 PositionKeyword = 0

if NewLetter > 25:

NewLetter = NewLetter - 26

   Ciphertext = Ciphertext + alphabet[NewLetter]

 return Ciphertext

 elif option == "d" or "decrypt":

   for i in plaintext_message:

   if i == "":

Ciphertext = Ciphertext + ""

   else:

NewLetter = (alphabet.index(i)-1) +
alphabet.index(Keyword[PositionKeyword])

PositionKeyword = Keyword + 1

if PositionKeyword == len(Keyword):

 PositionKeyword = 0

if NewLetter > 25:

 NewLetter = NewLetter - 26

   Ciphertext = Ciphertext + alphabet[NewLetter]

 return Ciphertext

 

 

#this makes the code abit more efficient

plaintext_message = getMessage()

Keyword = getKey()

Ciphertext = EncryptionOrDecryption(plaintext_message, Keyword)

 

#displays the Encyrpted/Decrypted message to the user 

print('Your translated text is:')

print(Ciphertext)

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


Re: [Tutor] Syntax error

2016-01-07 Thread Cameron Simpson

On 07Jan2016 13:15, Sarah Rasco  wrote:

Alan - I realized I did that right after I sent this email. However, I
can't run it in the windows or python prompts.

Here is my document:
[image: Inline image 1]
When I try to run it in the windows prompt I get:
[image: Inline image 2]

[...]

Hi Sarah,

The tutor list and the main python-list strips attachments, so we cannot see 
your images.  Please cut/paste the text as text instead of using screenshots.



I also tried to run it in my windows command prompt. I put in cd C:\python
and it gave me the python prompt.


I think you're misreading the Windows command prompt which recites the current 
folder. This:


 C:\python>

is still the Window command prompt. It is also probably not where you should do 
your python work unless you personally made this folder specially. Where did 
you save your "hello.py" file? That is probably where you should cd.



Then, when I tried to open the file by
typing python hello.py, I was given a syntax error again. Does anyone have
any suggestions as to what the problem could be?


Please cut/paste the text of your hello.py file and a complete transcript of 
the syntax error (all the lines).


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


Re: [Tutor] Syntax error

2016-01-07 Thread Sarah Rasco
Alan - I realized I did that right after I sent this email. However, I
can't run it in the windows or python prompts.

Here is my document:
[image: Inline image 1]
When I try to run it in the windows prompt I get:
[image: Inline image 2]

Or in the python prompt:
[image: Inline image 3]

And the file is definitely in there...
[image: Inline image 4]



On Thu, Jan 7, 2016 at 8:40 AM, Sarah Rasco  wrote:

> Hello,
>
> I'm new to programming and was told that Python would be a good language
> to start with. I downloaded version 3.5.1, and I have Windows 10.
>
> In IDLE, I typed print ("Hello, world!") and hit enter, and it returned
> the message. I saved the file as hello.py in C:\python. Then, when I tried
> to run it in IDLE, I got a syntax error and it highlighted the '5' in the
> prompt 'python 3.5.1'.
>
> I also tried to run it in my windows command prompt. I put in cd C:\python
> and it gave me the python prompt. Then, when I tried to open the file by
> typing python hello.py, I was given a syntax error again. Does anyone have
> any suggestions as to what the problem could be?
>
> Thank you!
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error

2016-01-07 Thread richard kappler
Hi Sarah!

instead of 'python hello.py', try

>>>import hello.py

using python hello.py works from the Linux command line (presumably Windows
as well) and it starts python then runs the hello.py script. From within
the python interpreter, you import the file and it executes.

HTH, Richard

On Thu, Jan 7, 2016 at 1:01 PM, Joel Goldstick 
wrote:

> On Thu, Jan 7, 2016 at 8:40 AM, Sarah Rasco 
> wrote:
>
> > Hello,
> >
> > I'm new to programming and was told that Python would be a good language
> to
> > start with. I downloaded version 3.5.1, and I have Windows 10.
> >
> > In IDLE, I typed print ("Hello, world!") and hit enter, and it returned
> the
> > message. I saved the file as hello.py in C:\python. Then, when I tried to
> > run it in IDLE, I got a syntax error and it highlighted the '5' in the
> > prompt 'python 3.5.1'.
> >
> > I also tried to run it in my windows command prompt. I put in cd
> C:\python
> > and it gave me the python prompt. Then, when I tried to open the file by
> > typing python hello.py, I was given a syntax error again. Does anyone
> have
> > any suggestions as to what the problem could be?
> >
> > Thank you!
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
> Welcome Sarah.
>
> Can you copy and paste the traceback (error message) that you get when you
> run your code.  Also, copy and paste your complete code text.
>
> --
> Joel Goldstick
> http://joelgoldstick.com/stats/birthdays
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 

All internal models of the world are approximate. ~ Sebastian Thrun
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error

2016-01-07 Thread Alan Gauld
On 07/01/16 13:40, Sarah Rasco wrote:

> In IDLE, I typed print ("Hello, world!") and hit enter, and it returned the
> message. I saved the file as hello.py in C:\python. Then, when I tried to
> run it in IDLE, I got a syntax error and it highlighted the '5' in the
> prompt 'python 3.5.1'.

I suspect you have accidentally saved the session instead of your program.
To save a program you need to go to File->New menu and
select a Python script.
That opens a new editor window (No >>> prompt).
Type your code (the print line in this case) into the editor window.
Now use File-> SaveAs to save your file as whatever you want to
call it (hello.py in this case)
Now you can either use the Run menu or execute it from the CMD box


The File->Save from the Python shell window saves everything
you have typed and that Python has printed. That is occasionally
but not often useful. For program code you need a new editor file


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Syntax error

2016-01-07 Thread Sarah Rasco
Hello,

I'm new to programming and was told that Python would be a good language to
start with. I downloaded version 3.5.1, and I have Windows 10.

In IDLE, I typed print ("Hello, world!") and hit enter, and it returned the
message. I saved the file as hello.py in C:\python. Then, when I tried to
run it in IDLE, I got a syntax error and it highlighted the '5' in the
prompt 'python 3.5.1'.

I also tried to run it in my windows command prompt. I put in cd C:\python
and it gave me the python prompt. Then, when I tried to open the file by
typing python hello.py, I was given a syntax error again. Does anyone have
any suggestions as to what the problem could be?

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


Re: [Tutor] syntax error

2015-09-18 Thread Nym City via Tutor
-Perfect. Thank you. 


 On Tuesday, September 15, 2015 5:00 AM, Alan Gauld 
 wrote:
   
 

 On 15/09/15 02:41, Nym City via Tutor wrote:
> Hello,
> I am also just trying to understand this code and could not understand the 
> print statement.I would have just used:
>  print('cost:$',gross_cost)
> Do you mind telling little bit about what:
> print('cost: ${:.2f}'.format(gross_cost))
> does do and why one would use this over my plain version?

When in doubt use the >>> prompt:

 >>> gross_cost = 4.6
 >>> print('cost: $',gross_cost)
cost: $4.6
 >>> print('cost: ${:.2f}'.format(gross_cost))
cost: $4.60

So the .2f forces the output to be formatted as a floating
point number with 2 digits after the decimal point.
And the format() inserts the values into the {} markers
in the string to which its attached. Another longer example:

 >>> quantity = 4
 >>> unit_cost = 4
 >>> tax = 0.1
 >>> print('''I bought {} items at ${:.2f} with {}% tax,
... making a total cost of: ${:.2f}
... '''.format(quantity,
...          unit_cost,
...          int(tax*100),
...          quantity * unit_cost * (1+tax)))
I bought 4 items at $4.00 with 10% tax
making a total cost of: $17.60

Notice this time that :.2f forced the integer unit_cost(4)
to be shown as a float with 2 decimal places(4.00).

There are lots of other codes you can use to modify the
formatting.

Check the language reference in the docs under 'formatting':

https://docs.python.org/3/library/string.html#formatstrings

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


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


Re: [Tutor] syntax error

2015-09-15 Thread Alan Gauld

On 15/09/15 02:41, Nym City via Tutor wrote:

Hello,
I am also just trying to understand this code and could not understand the 
print statement.I would have just used:
  print('cost:$',gross_cost)
Do you mind telling little bit about what:
print('cost: ${:.2f}'.format(gross_cost))
does do and why one would use this over my plain version?


When in doubt use the >>> prompt:

>>> gross_cost = 4.6
>>> print('cost: $',gross_cost)
cost: $4.6
>>> print('cost: ${:.2f}'.format(gross_cost))
cost: $4.60

So the .2f forces the output to be formatted as a floating
point number with 2 digits after the decimal point.
And the format() inserts the values into the {} markers
in the string to which its attached. Another longer example:

>>> quantity = 4
>>> unit_cost = 4
>>> tax = 0.1
>>> print('''I bought {} items at ${:.2f} with {}% tax,
... making a total cost of: ${:.2f}
... '''.format(quantity,
...   unit_cost,
...   int(tax*100),
...   quantity * unit_cost * (1+tax)))
I bought 4 items at $4.00 with 10% tax
making a total cost of: $17.60

Notice this time that :.2f forced the integer unit_cost(4)
to be shown as a float with 2 decimal places(4.00).

There are lots of other codes you can use to modify the
formatting.

Check the language reference in the docs under 'formatting':

https://docs.python.org/3/library/string.html#formatstrings

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Syntax error and EOL Error

2015-09-15 Thread Nym City via Tutor
-Thank you very much for your feedback. It was definitely helpful. I will try 
to stay consistent with my coding style in the future projects.
 
 


 On Sunday, September 13, 2015 3:01 PM, Danny Yoo  
wrote:
   
 

 On Sun, Sep 13, 2015 at 7:20 AM, Nym City via Tutor  wrote:
> Hello,
> Sorry for the late response. It took me sometime to find the solution. Below 
> is my updated code which seems to be working fine now. Just wanted to share 
> with the group here.
>
> import csv
> DomainList = []
>
> domains = open('domainlist.csv', 'r')
> DomainList = csv.reader(domains)
> DomainList = [column[1] for column in DomainList]
> strip_list = [item.rstrip('/') for item in DomainList]
> print('\n'.join(strip_list))


Style suggestions.

1.  The initial assignment of:

    DomainList = []

can be omitted: the code does another assignment that completely
ignores the initial value.


2.  The reassignment of DomainList to the result of csv.reader() is
confusing, because the new value isn't of the same type as the old
value.  I'd recommend that your program set aside a separate variable
name for the csv reader.  Call it "DomainListCSV" or something that
can be distinguished from the list of domains that your program is
collecting.

###
import csv

domains = open('domainlist.csv', 'r')
DomainListCSV = csv.reader(domains)
DomainList = [column[1] for column in DomainListCSV]
strip_list = [item.rstrip('/') for item in DomainList]
print('\n'.join(strip_list))


That way, if you see the word "DomainList" in your program, its
conceptual meaning is more stable: its meaning doesn't have to change
from one statement to the next.  Assigning to a variable just once
makes the program easier to understand.

(That being said, we might have technical reasons for doing variable
re-assignment.  But such cases aren't as prevalent as one might
expect!)



3.  Finally, it might be good to stick with a single style for naming
variables.  You're using both underscored names and CapCased names.
Consistency suggests that we pick a style and stick with it throughout
the program.  Doing an eclectic mix of naming conventions hurts
readability a bit.

If we stick with underscored names:

###
import csv

domain_file = open('domainlist.csv', 'r')
domains_csv = csv.reader(domain_file)
domain_list = [column[1] for column in domains_csv]
strip_list = [item.rstrip('/') for item in domain_list]
print('\n'.join(strip_list))


that would be one way to correct this issue.  Or use CapWords.  The
main point is: try to use a single style that's shared across the
program as a whole.


Hope this helps!


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


Re: [Tutor] syntax error

2015-09-15 Thread Nym City via Tutor
Hello,
I am also just trying to understand this code and could not understand the 
print statement.I would have just used:
 print('cost:$',gross_cost)
Do you mind telling little bit about what: 
print('cost: ${:.2f}'.format(gross_cost))
does do and why one would use this over my plain version?


 Thank you. 


 On Monday, September 14, 2015 2:46 PM, Alan Gauld 
 wrote:
   
 

 On 14/09/15 19:25, Joel Goldstick wrote:
> On Mon, Sep 14, 2015 at 1:20 PM, Sarah  wrote:
>
>> Hi
>> What's wrong with the following code?
>>
>> def main()
>>        lunch = int(input('How many hours did you eat?'))
>>        cost = float(input('Enter the hourly cost: '))
>>        gross_cost = lunch * cost
>>        print('cost:$', format(cost, '.2f'), sep='')
>> main()
>>
>>
>> I get the error File "", line 6
>>
>> Thanks, Sarah
>>
>
> You forgot the : after def main(...):

Also your print line is, I suspect, wrong.
I assume you want to print gross_cost not cost?

You could also use the format method of the string which
tends to be more flexible:

print('cost: ${:.2f}'.format(gross_cost))

hth
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


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


Re: [Tutor] syntax error

2015-09-14 Thread Alan Gauld

On 14/09/15 19:25, Joel Goldstick wrote:

On Mon, Sep 14, 2015 at 1:20 PM, Sarah  wrote:


Hi
What's wrong with the following code?

def main()
lunch = int(input('How many hours did you eat?'))
cost = float(input('Enter the hourly cost: '))
gross_cost = lunch * cost
print('cost:$', format(cost, '.2f'), sep='')
main()


I get the error File "", line 6

Thanks, Sarah



You forgot the : after def main(...):


Also your print line is, I suspect, wrong.
I assume you want to print gross_cost not cost?

You could also use the format method of the string which
tends to be more flexible:

print('cost: ${:.2f}'.format(gross_cost))

hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] syntax error

2015-09-14 Thread Steven D'Aprano
On Mon, Sep 14, 2015 at 01:20:55PM -0400, Sarah wrote:
> Hi
> What's wrong with the following code?
> 
> def main()
>lunch = int(input('How many hours did you eat?'))
>cost = float(input('Enter the hourly cost: '))
>gross_cost = lunch * cost
>print('cost:$', format(cost, '.2f'), sep='')
> main()
> 
> 
> I get the error File "", line 6

The above should be fine when saved and run from a .py file, but at the 
interactive interpreter, you need to leave a blank line after functions.

Try leaving a blank after the print(...) line and before main().


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


Re: [Tutor] syntax error

2015-09-14 Thread Joel Goldstick
On Mon, Sep 14, 2015 at 1:20 PM, Sarah  wrote:

> Hi
> What's wrong with the following code?
>
> def main()
>lunch = int(input('How many hours did you eat?'))
>cost = float(input('Enter the hourly cost: '))
>gross_cost = lunch * cost
>print('cost:$', format(cost, '.2f'), sep='')
> main()
>
>
> I get the error File "", line 6
>
> Thanks, Sarah
>

You forgot the : after def main(...):

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



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


[Tutor] syntax error

2015-09-14 Thread Sarah
Hi
What's wrong with the following code?

def main()
   lunch = int(input('How many hours did you eat?'))
   cost = float(input('Enter the hourly cost: '))
   gross_cost = lunch * cost
   print('cost:$', format(cost, '.2f'), sep='')
main()


I get the error File "", line 6

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


Re: [Tutor] Syntax error and EOL Error

2015-09-13 Thread Danny Yoo
On Sun, Sep 13, 2015 at 7:20 AM, Nym City via Tutor  wrote:
> Hello,
> Sorry for the late response. It took me sometime to find the solution. Below 
> is my updated code which seems to be working fine now. Just wanted to share 
> with the group here.
>
> import csv
> DomainList = []
>
> domains = open('domainlist.csv', 'r')
> DomainList = csv.reader(domains)
> DomainList = [column[1] for column in DomainList]
> strip_list = [item.rstrip('/') for item in DomainList]
> print('\n'.join(strip_list))


Style suggestions.

1.  The initial assignment of:

DomainList = []

can be omitted: the code does another assignment that completely
ignores the initial value.


2.  The reassignment of DomainList to the result of csv.reader() is
confusing, because the new value isn't of the same type as the old
value.  I'd recommend that your program set aside a separate variable
name for the csv reader.  Call it "DomainListCSV" or something that
can be distinguished from the list of domains that your program is
collecting.

###
import csv

domains = open('domainlist.csv', 'r')
DomainListCSV = csv.reader(domains)
DomainList = [column[1] for column in DomainListCSV]
strip_list = [item.rstrip('/') for item in DomainList]
print('\n'.join(strip_list))


That way, if you see the word "DomainList" in your program, its
conceptual meaning is more stable: its meaning doesn't have to change
from one statement to the next.  Assigning to a variable just once
makes the program easier to understand.

(That being said, we might have technical reasons for doing variable
re-assignment.  But such cases aren't as prevalent as one might
expect!)



3.  Finally, it might be good to stick with a single style for naming
variables.  You're using both underscored names and CapCased names.
Consistency suggests that we pick a style and stick with it throughout
the program.  Doing an eclectic mix of naming conventions hurts
readability a bit.

If we stick with underscored names:

###
import csv

domain_file = open('domainlist.csv', 'r')
domains_csv = csv.reader(domain_file)
domain_list = [column[1] for column in domains_csv]
strip_list = [item.rstrip('/') for item in domain_list]
print('\n'.join(strip_list))


that would be one way to correct this issue.  Or use CapWords.  The
main point is: try to use a single style that's shared across the
program as a whole.


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


Re: [Tutor] Syntax error and EOL Error

2015-09-13 Thread Nym City via Tutor
Hello,
Sorry for the late response. It took me sometime to find the solution. Below is 
my updated code which seems to be working fine now. Just wanted to share with 
the group here.

import csv
DomainList = []

domains = open('domainlist.csv', 'r')
DomainList = csv.reader(domains)
DomainList = [column[1] for column in DomainList]
strip_list = [item.rstrip('/') for item in DomainList]
print('\n'.join(strip_list))
 Thank you. 


 On Monday, September 7, 2015 5:25 AM, Alan Gauld 
 wrote:
   
 

 On 07/09/15 01:40, Nym City via Tutor wrote:
> Hello,
> Thank you for your response. I have made updates and here is the new code:
> import csv
> DomainList = []
>
> domains = open('domainlist.csv', 'rb')
> DomainList = csv.reader(domains)
> DomainList = [column[1] for column in DomainList(str.rstrip('/'))]

Since DomainList is a csv.reader object what made you think you could 
call it with a string argument? You were not doing that previously?

> For "DomainList = [column[1] for column in DomainList(str.rstrip('/'))]"
> line, I am getting following error:TypeError: '_csv.reader' object is not 
> callable

Which is true, and should be obvious how to fix. Stop calling it.
That means don't have parentheses after it.

> Doing some research, i thought it might be because I am importing
 > the csv as 'r' only

You are not importing the csv as 'r' you are opening your file as 'r'.
This has nothing to do with the error.
That is because you are calling a non callable object.

> Also, not sure if the next error is because of the above issue but
 > I get syntax error when I do the last print

Can you tell us how you managed to get that second error?
The interpreter should have stopped after the first error so you
should never get a second error. You must have modified the
code in some way.

You would need to show us the actual code you ran to reach the print 
statement, otherwise we can't begin to guess what might be causing the 
syntax error.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


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


Re: [Tutor] Syntax error and EOL Error

2015-09-07 Thread Alan Gauld

On 07/09/15 01:40, Nym City via Tutor wrote:

Hello,
Thank you for your response. I have made updates and here is the new code:
import csv
DomainList = []

domains = open('domainlist.csv', 'rb')
DomainList = csv.reader(domains)
DomainList = [column[1] for column in DomainList(str.rstrip('/'))]


Since DomainList is a csv.reader object what made you think you could 
call it with a string argument? You were not doing that previously?



For "DomainList = [column[1] for column in DomainList(str.rstrip('/'))]"
line, I am getting following error:TypeError: '_csv.reader' object is not 
callable


Which is true, and should be obvious how to fix. Stop calling it.
That means don't have parentheses after it.


Doing some research, i thought it might be because I am importing

> the csv as 'r' only

You are not importing the csv as 'r' you are opening your file as 'r'.
This has nothing to do with the error.
That is because you are calling a non callable object.


Also, not sure if the next error is because of the above issue but

> I get syntax error when I do the last print

Can you tell us how you managed to get that second error?
The interpreter should have stopped after the first error so you
should never get a second error. You must have modified the
code in some way.

You would need to show us the actual code you ran to reach the print 
statement, otherwise we can't begin to guess what might be causing the 
syntax error.



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] Syntax error and EOL Error

2015-09-07 Thread Nym City via Tutor
Hello,
Thank you for your response. I have made updates and here is the new code:
import csv
DomainList = []

domains = open('domainlist.csv', 'rb')
DomainList = csv.reader(domains)
DomainList = [column[1] for column in DomainList(str.rstrip('/'))]
print(DomainList)
For "DomainList = [column[1] for column in DomainList(str.rstrip('/'))]" line, 
I am getting following error:TypeError: '_csv.reader' object is not callable
Doing some research, i thought it might be because I am importing the csv as 
'r' only so i tried changing it to 'rb' and 'w' but received the same error.
Also, not sure if the next error is because of the above issue but I get syntax 
error when I do the last print and I do not see any syntax issue with it.
As always, thanks in advance. 
 Thank you. 


 On Friday, September 4, 2015 3:23 AM, Peter Otten <__pete...@web.de> wrote:
   
 

 Nym City via Tutor wrote:

>  import csv
> DomainList = []
> 
> domains = open('domainlist.csv', 'r')
> DomainList = csv.reader(domains)
> DomainList = [column[1] for column in DomainList]
> DomainList = (str(DomainList).rstrip('/')
> print('\n'.join(DomainList))
> 
> 
> I keep getting EOL error on the second the last line and syntax error on
> the last print line. Even when I change the print line to say the
> following: print(DomainList) Please advise. Thank you in advance.
> Thank you.

Look at the lines preceding the one triggering the SyntaxError. Usually 
there is an opening (, [ or { which doesn't have a matching closing 
counterpart. 

In your case count the parens in the line

> DomainList = (str(DomainList).rstrip('/')

By the way, even without error this line will not have the desired effect.
Given 

>>> DomainList = ["facebook.com/", "twitter.com/"]

converting to string gives

>>> str(DomainList)
"['facebook.com/', 'twitter.com/']"

and as that doesn't end with a "/" applying the rstrip() method has no 
effect. Instead you can modify the line

> DomainList = [column[1] for column in DomainList]

where you can invoke the rstrip() method on every string in the list.

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


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


Re: [Tutor] Syntax error and EOL Error

2015-09-04 Thread Peter Otten
Nym City via Tutor wrote:

>  import csv
> DomainList = []
> 
> domains = open('domainlist.csv', 'r')
> DomainList = csv.reader(domains)
> DomainList = [column[1] for column in DomainList]
> DomainList = (str(DomainList).rstrip('/')
> print('\n'.join(DomainList))
> 
> 
> I keep getting EOL error on the second the last line and syntax error on
> the last print line. Even when I change the print line to say the
> following: print(DomainList) Please advise. Thank you in advance.
> Thank you.

Look at the lines preceding the one triggering the SyntaxError. Usually 
there is an opening (, [ or { which doesn't have a matching closing 
counterpart. 

In your case count the parens in the line

> DomainList = (str(DomainList).rstrip('/')

By the way, even without error this line will not have the desired effect.
Given 

>>> DomainList = ["facebook.com/", "twitter.com/"]

converting to string gives

>>> str(DomainList)
"['facebook.com/', 'twitter.com/']"

and as that doesn't end with a "/" applying the rstrip() method has no 
effect. Instead you can modify the line

> DomainList = [column[1] for column in DomainList]

where you can invoke the rstrip() method on every string in the list.

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


[Tutor] Syntax error and EOL Error

2015-09-03 Thread Nym City via Tutor
Hello,
I am working with a csv file that has following sample data:
Rank    URL    Linking Root Domains
1    facebook.com/    9616487
2    twitter.com/    6454936
3    google.com/    5868081
4    youtube.com/    5442206
5    wordpress.org/    4051288

In my program, I am reading in this csv file, taking only data from the second 
column and striping off the leading "/"
 import csv
DomainList = []

domains = open('domainlist.csv', 'r')
DomainList = csv.reader(domains)
DomainList = [column[1] for column in DomainList]
DomainList = (str(DomainList).rstrip('/')
print('\n'.join(DomainList))


I keep getting EOL error on the second the last line and syntax error on the 
last print line. Even when I change the print line to say the following:
print(DomainList)
Please advise. Thank you in advance. 
 Thank you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error with raw input

2014-11-12 Thread Steven D'Aprano
On Wed, Nov 12, 2014 at 04:38:51PM +0530, Vaibhav Banait wrote:
> Hi
> I am new to python. I learnt (!) using  raw_input a day back. Attempt to
> use has resulted in error. I am not able to spot a problem in syntax.

What makes you think it is a problem with syntax?

This is what happens when you have a syntax error:

py> 23 42 +
  File "", line 1
23 42 +
^
SyntaxError: invalid syntax


Look at the error you get instead: it doesn't say "SyntaxError", does 
it? It says "NameError".

NameError: name 'raw_input' is not defined


The reason is that in Python 3, "raw_input" has been renamed to just 
"input".



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


Re: [Tutor] syntax error with raw input

2014-11-12 Thread wesley chun
Slightly hijacking this thread a bit, specifically Alan's reply, if anyone
is averse to installing multiple versions of Python on their computers, you
can always access a Python interpreter from a browser window.

Here are a collection I've put together. Most are Python 2, but the top
pair also support Python 3:

   - http://ideone.com (2.x & 3.x)
   - http://colabv6.dan.co.jp/lleval.html (2.x & 3.x)
   - http://doc.pyschools.com/console
   - http://repl.it/languages/Python
   - http://skulpt.org (pure JS implementation; allows turtle)
   - http://pythonwebconsole.thomnichols.org
   - http://shell.appspot.com (Google App Engine + libraries)
   - http://codepad.org
   - http://lotrepls.appspot.com
   - http://datamech.com/devan/trypython/trypython.py

Cheers,
--Wesley

On Wed, Nov 12, 2014 at 9:11 AM, Alan Gauld 
wrote:

> On 12/11/14 11:08, Vaibhav Banait wrote:
>
>> Hi
>> I am new to python. I learnt (!) using  raw_input a day back. Attempt to
>> use has resulted in error. I am not able to spot a problem in syntax. I
>> am using python 3.4.2. Kindly help
>>
>
> Looks like you are reading a v2 book/tutorial but using v3.
>
> In v3 several key changes were made to Python including the renaming of
> raw_input() to input().
>
> The other big change was making print a function so you now *must* put
> parentheses around anything you want to print.
>
> ie
>
> print 'hello'  # Python v2
>
> becomes
>
> print('hello')   # python v3
>
> There are numerous other small changes so it would be better for you to
> either find a v3 tutorial (you could try mine! :-) or install Python v2.7
> while you are learning.
>
>
> --
> 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
>



-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
+wesley chun  : wescpy at gmail : @wescpy

Python training & consulting : http://CyberwebConsulting.com
"Core Python" books : http://CorePython.com
Python blog: http://wescpy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error with raw input

2014-11-12 Thread Alan Gauld

On 12/11/14 11:08, Vaibhav Banait wrote:

Hi
I am new to python. I learnt (!) using  raw_input a day back. Attempt to
use has resulted in error. I am not able to spot a problem in syntax. I
am using python 3.4.2. Kindly help


Looks like you are reading a v2 book/tutorial but using v3.

In v3 several key changes were made to Python including the renaming of 
raw_input() to input().


The other big change was making print a function so you now *must* put 
parentheses around anything you want to print.


ie

print 'hello'  # Python v2

becomes

print('hello')   # python v3

There are numerous other small changes so it would be better for you to 
either find a v3 tutorial (you could try mine! :-) or install Python 
v2.7 while you are learning.



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


Re: [Tutor] syntax error with raw input

2014-11-12 Thread Chris Warrick
On Wed, Nov 12, 2014 at 12:08 PM, Vaibhav Banait
 wrote:
> Hi
> I am new to python. I learnt (!) using  raw_input a day back. Attempt to use
> has resulted in error. I am not able to spot a problem in syntax. I am using
> python 3.4.2. Kindly help
>
>
> a = raw_input("Write down your name: ")
>
> Output:
>
>
> Traceback (most recent call last):
>   File "", line 1, in 
> a = raw_input("Write down your name: ")
> NameError: name 'raw_input' is not defined
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

In Python 3, raw_input() was renamed to input().

a = input("Write down your name: ")

Note that input() is also a thing in Python 2, but you shouldn’t use
that one for security reasons.  Python 3’s is fine though.

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


[Tutor] syntax error with raw input

2014-11-12 Thread Vaibhav Banait
Hi
I am new to python. I learnt (!) using  raw_input a day back. Attempt to
use has resulted in error. I am not able to spot a problem in syntax. I am
using python 3.4.2. Kindly help


a = raw_input("Write down your name: ")

Output:


Traceback (most recent call last):
  File "", line 1, in 
a = raw_input("Write down your name: ")
NameError: name 'raw_input' is not defined
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error when attempting simple urllib.request.urlopen item

2013-07-10 Thread Dave Angel

On 07/09/2013 04:00 PM, Paul Smith wrote:

Tutor-

Ok newbie to coding here attempting to build controlled web scraper and
have followed several books-tutorials and am failing at step one.

This is the 3.3.1 code I am trying to run..
===
import urllib.request

htmltext = urllib.request.urlopen("http://google.com";).read

print htmltext
===
Other version...
===
#try py url open 7

import urllib.request
res = urllib.request.urlopen('http://python.org/')
html = res.read()
print = html
close res
input = ("Press enter to exit")
===

so when I run what I think is proper 3.3.1 python code it hangs up with
syntax error with the idle shell red highlighting the last print reference
i.e. "htmltext"  or "html".

What is this humble newbie not getting?



The first thing you're missing is that print() is a function in Python 
3.3  So you need   print(htmltext)


Once you're past that, you'll find that you need parentheses if you want 
to call the read() method.



--
DaveA

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


Re: [Tutor] syntax error when attempting simple urllib.request.urlopen item

2013-07-10 Thread Hugo Arts
On Tue, Jul 9, 2013 at 10:00 PM, Paul Smith wrote:

> Tutor-
>
> Ok newbie to coding here attempting to build controlled web scraper and
> have followed several books-tutorials and am failing at step one.
>
> This is the 3.3.1 code I am trying to run..
> ===
> import urllib.request
>
> htmltext = urllib.request.urlopen("http://google.com";).read
>
> print htmltext
> ===
> Other version...
> ===
> #try py url open 7
>
> import urllib.request
> res = urllib.request.urlopen('http://python.org/')
> html = res.read()
> print = html
> close res
> input = ("Press enter to exit")
> ===
>
> so when I run what I think is proper 3.3.1 python code it hangs up with
> syntax error with the idle shell red highlighting the last print reference
> i.e. "htmltext"  or "html".
>
> What is this humble newbie not getting?
>
>
>
I'm fairly certain that what you're missing is that in python 3.x, print is
no longer a statement but a function. The correct line would be
"print(htmltext)".

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


[Tutor] syntax error when attempting simple urllib.request.urlopen item

2013-07-10 Thread Paul Smith
Tutor-

Ok newbie to coding here attempting to build controlled web scraper and
have followed several books-tutorials and am failing at step one.

This is the 3.3.1 code I am trying to run..
===
import urllib.request

htmltext = urllib.request.urlopen("http://google.com";).read

print htmltext
===
Other version...
===
#try py url open 7

import urllib.request
res = urllib.request.urlopen('http://python.org/')
html = res.read()
print = html
close res
input = ("Press enter to exit")
===

so when I run what I think is proper 3.3.1 python code it hangs up with
syntax error with the idle shell red highlighting the last print reference
i.e. "htmltext"  or "html".

What is this humble newbie not getting?

Best regards,

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


Re: [Tutor] syntax error

2012-05-14 Thread bob gailer

On 5/14/2012 6:14 AM, Keitaro Kaoru wrote:

hello~ is NOT a good subject


i resent it but if that doesnt work. cause i sent it to myself also
looks fine on my gmail.. but heres a link to pastebin

http://pastebin.com/Jp7VJKGB


There are still numerous errors that prevent the program from compiling.

PLEASE ONLY PASTEBIN code that we can run!
Line 26 ends with ; should be ))
Line 28 is split
Line 31 - is that a comment if so put # in front of it.
Line 38-51 must be indented
Line 44   ifdata[1] == "join":
Line 51 will never be executed.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] syntax error

2012-05-14 Thread bob gailer

I have changed the subject to "syntax error".

Please always post a meaningful subject.

On 5/14/2012 5:58 AM, Keitaro Kaoru wrote:

sorry if i keep missing this up.

hey. Austin here for some reason this command. all it does it produces the
error message at the bottom..

The code you sent has numerous errors.

How did you miss all the other errors?

Are you using an IDE to edit the code? An IDE will help you locate the 
errors.


I corrected the errors (so the program compiles) and put a copy in 
http://pastebin.com/zWcD7gnT.


I have no idea if all the indentation is correct, as I can only guess, 
and don't want to spend time doing better guessing.


Please sign up with pastebin and post your code there. That will 
guarantee we can copy it as you wrote it.


Also please refer to your program as a program or script. It is not a 
command.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] syntax error

2012-05-13 Thread Alan Gauld

On 13/05/12 10:44, Steven D'Aprano wrote:


and if I look at the email which started this thread, Keitaro Kaoru's
email with no subject line, I see it has the same message ID:

Message-ID:



so my guess is that Thunderbird is just stupid.


Like Dave I am on Thunderbird 12 and it is threading the messages
just fine... But I never noticed a problem with T/Bird 3.1 either.


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

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


Re: [Tutor] syntax error

2012-05-13 Thread Devin Jeanpierre
On Sun, May 13, 2012 at 5:44 AM, Steven D'Aprano  wrote:
> Devin Jeanpierre wrote:
>>
>> On Sat, May 12, 2012 at 10:29 PM, bob gailer  wrote:
>>>
>>> oh - and always provide a specific meaningful subject
>>
>>
>> My client has no idea what thread this post came from.
>>
>> Is it supposed to?
>
>
>
> What's your client? I'm using Thunderbird, and it too doesn't have any idea.

The gmail web interface.

> I see that Bob's email does have an In-Reply-To header:
>
> In-Reply-To:
> 
>
> and if I look at the email which started this thread, Keitaro Kaoru's email
> with no subject line, I see it has the same message ID:
>
> Message-ID:
> 
>
>
> so my guess is that Thunderbird is just stupid.

Welp. Not much I can do here. I should probably switch to a desktop
client at some point.

Thanks for the detective work.

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


Re: [Tutor] syntax error

2012-05-13 Thread Dave Angel
On 05/13/2012 05:44 AM, Steven D'Aprano wrote:
> Devin Jeanpierre wrote:
>> On Sat, May 12, 2012 at 10:29 PM, bob gailer  wrote:
>>> oh - and always provide a specific meaningful subject
>>
>> My client has no idea what thread this post came from.
>>
>> Is it supposed to?
>
>
> What's your client? I'm using Thunderbird, and it too doesn't have any
> idea.
>
> I see that Bob's email does have an In-Reply-To header:
>
> In-Reply-To:
> 
>
> and if I look at the email which started this thread, Keitaro Kaoru's
> email with no subject line, I see it has the same message ID:
>
> Message-ID:
> 
>
>
> so my guess is that Thunderbird is just stupid.
>
>

But my copy of Thunderbird (12.0.1, running on Linux) recognized these
as being the same thread as Keitaro Kaoru's message, and combined them
properly.



-- 

DaveA

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


Re: [Tutor] syntax error

2012-05-13 Thread Steven D'Aprano

Devin Jeanpierre wrote:

On Sat, May 12, 2012 at 10:29 PM, bob gailer  wrote:

oh - and always provide a specific meaningful subject


My client has no idea what thread this post came from.

Is it supposed to?



What's your client? I'm using Thunderbird, and it too doesn't have any idea.

I see that Bob's email does have an In-Reply-To header:

In-Reply-To: 


and if I look at the email which started this thread, Keitaro Kaoru's email 
with no subject line, I see it has the same message ID:


Message-ID: 


so my guess is that Thunderbird is just stupid.



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


Re: [Tutor] syntax error

2012-05-12 Thread Devin Jeanpierre
On Sat, May 12, 2012 at 10:29 PM, bob gailer  wrote:
> oh - and always provide a specific meaningful subject

My client has no idea what thread this post came from.

Is it supposed to?

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


Re: [Tutor] syntax error

2012-05-12 Thread bob gailer

oh - and always provide a specific meaningful subject

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Syntax error help

2012-03-31 Thread S.Irfan Rizvi
Its failing i can't able to unsubcribe
please remove me from its not going to Span either









*Error: **Authentication failed.*Tutor list: member options login pageIn
order to change your membership option, you must first log in by giving
your email address  and
membership password in the section below. If you don't remember your
membership password, you can have it emailed to you by clicking on the
button below. If you just want to unsubscribe from this list, click on the *
Unsubscribe* button and a
confirmation message
will be sent to you.

*Important:* From this point on, you must have cookies enabled in your
browser, otherwise none of your changes will take effect.
Email address:
Password:
UnsubscribeBy clicking on the *Unsubscribe* button, a confirmation message
will be emailed to you. This message will have a link that you should click
on to complete the removal process (you can also
confirm by
email; see the instructions in the confirmation message).Password reminderBy
clicking on the *Remind* button, your password will be emailed to you.




On Mar 31, 2012 6:51 PM, "Alan Gauld"  wrote:

> On 31/03/12 03:33, S.Irfan Rizvi wrote:
>
>> Please remove me from listi can't do itthey are doing it Attention
>> __**_
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/**mailman/listinfo/tutor
>>
>
> Only you could have joined the list and only you can unsubscribe.
> Go to the web page and follow the instructions.
>
> If it doesn't work email me and I'll try to figure out what's
> going wrong.
>
> --
> Alan G
> Tutor list moderator
> (and just home from vacation...)
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error help

2012-03-31 Thread Alan Gauld

On 31/03/12 03:33, S.Irfan Rizvi wrote:

Please remove me from listi can't do itthey are doing it Attention
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Only you could have joined the list and only you can unsubscribe.
Go to the web page and follow the instructions.

If it doesn't work email me and I'll try to figure out what's
going wrong.

--
Alan G
Tutor list moderator
(and just home from vacation...)

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


Re: [Tutor] Syntax error help

2012-03-31 Thread bob gailer

Thank you for posting your code.

Did you forget to reply-all? I am copying this to the list this time.

You apparantly misunderstood my question about what you do to run the 
program. You said " I import then call the first function  (the 
displaymenu) or I have it called in the code it does it automatically".


I am running out of patience trying to get from you what we as a Tutor 
List need in order to help you.


Please answer the following:
What operating system are you using (Windows, Linux, Mac, ...)
WHAT DO YOU DO RUN THE PROGRAM. I gave detailed examples of potential 
answers (see below). Do you not understand what I'm looking for?


On 3/30/2012 11:22 PM, chris knarvik wrote:
Also here is my revised code with what i call a 'programmers error' 
let me know  if you  see it because i dont


Why all the imports - you are not using any math, os or sys code. Also 
You should not do 2 different imports from math. It is better to drop 
the from ...

import math
import os, sys
from math import *

def displaymenu():
print 'please make a selection';
print 'Area (1)';
choice = raw_input('enter selection number')

OK time to learn how to debug.
Since the code goes from if to print, the if condition (choice == 1) 
must be False.

What datatype does raw_input give you?
Why would that cause the condition to be False?
One way to answer that is to read the manual regarding raw_input.
Another is to use print statements with type() to tell you the types.
Therefore just before the if put
print type(choice), type(1)


if choice == 1:
   selctiona()
else:
print'choice',choice,'is wrong'
print"why god wont this thing work"


def areamenu():
print 'Square (1)'
print 'triangle (2)'
print 'rectangle (3)'
print 'trapazoid (4)'
print 'circle (5)'

def selctiona():
areamenu();
choicea = raw_input('enter selection');
if choicea == 1:
   squareacalc()

else:
print 'why god why'

def squareacalc():
sidelength = input('enter side length: ')
print "The Area Is", sidelength **2


You don't seem to call reloadarea!

def reloadarea():
   print 'would you like to calculate again'
   choicer = raw_input('yes(1) or no(2)')
   if choicer == 1:
This is called recursion. It is better in this kind of program to put 
the entire thing in a while loop(see below)*  rather than to use a 
recursive call.

   displaymenu()
   elif choicer == 2:
   print 'goodbye'

displaymenu()

i cant get past the display menu i get this result
please make a selection
Area (1)
enter selection number1
choice 1 is wrong
why god wont this thing work

>>>
let me know if you can see where i went wrong


I hope the guidance I gave above helps.

* Using a while loop instead of recursion:
while True:
  displaymenu()
  print 'would you like to calculate again'
  choicer = raw_input('yes(1) or no(2)')
  if choicer == 2: # this also will not work, for the same reason that 
choice == 1 does not work. Once you fix choice == 1 then you can also 
fix this.

break






what do you mean what do i do to run it

There are several ways to execute (run) a Python program.
You can double-click the file in an explorer.
You can at a command prompt type (e.g.) >python Area.py
or you can start an interactive session then type >>>import Area
or you can use an IDE such as IDLE.
 within IDLE you can write the program in an edit window then RUN
 or you can use the interactive window and type >>>import Area
Which of these (or what else) do you do 





--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Syntax error help

2012-03-30 Thread S.Irfan Rizvi
Please remove me from listi can't do itthey are doing it Attention
On Mar 30, 2012 9:21 PM, "bob gailer"  wrote:

> Please always reply-all so a copy goes to the list.
>
> On 3/30/2012 8:01 PM, chris knarvik wrote:
>
>> that was incomplete it was supposed to be ive fixed most of my problems
>> with your help
>>
>
> That's great. Would you post the correct program so we can all learn? And
> possibly make other helpful suggestions.
>
>  what do you mean what do i do to run it
>>
> There are several ways to execute (run) a Python program.
> You can double-click the file in an explorer.
> You can at a command prompt type (e.g.) >python Area.py
> or you can start an interactive session then type >>>import Area
> or you can use an IDE such as IDLE.
>  within IDLE you can write the program in an edit window then RUN
>  or you can use the interactive window and type >>>import Area
> Which of these (or what else) do you do
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error help

2012-03-30 Thread bob gailer

Please always reply-all so a copy goes to the list.

On 3/30/2012 8:01 PM, chris knarvik wrote:
that was incomplete it was supposed to be ive fixed most of my 
problems with your help


That's great. Would you post the correct program so we can all learn? 
And possibly make other helpful suggestions.



what do you mean what do i do to run it

There are several ways to execute (run) a Python program.
You can double-click the file in an explorer.
You can at a command prompt type (e.g.) >python Area.py
or you can start an interactive session then type >>>import Area
or you can use an IDE such as IDLE.
  within IDLE you can write the program in an edit window then RUN
  or you can use the interactive window and type >>>import Area
Which of these (or what else) do you do

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Syntax error help

2012-03-30 Thread bob gailer

On 3/30/2012 6:20 PM, x23ch...@gmail.com wrote:

Thanks I've fixed
Great. Please share with us your new program and tell us what you do to 
run it.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Syntax error help

2012-03-30 Thread x23ch...@gmail.com
Thanks I've fixed

Sent from my iPod

On Mar 30, 2012, at 5:30 PM, bob gailer  wrote:

> On 3/30/2012 4:26 PM, chris knarvik wrote:
>> Alright i have been trying to right a (relatively) simple to calculate area 
>> and volume below is my current working code
> 
> Suggestion: start with a VERY SIMPLE program and get that working. Then add 
> one new feature at a time.
> 
> Is the following in Area.py? If it is then the traceback could not have come 
> from importing this code, because line 10 does not mention areamenu().
> In fact areamenu() appears ONLY in line 1, but not by itself!
> 
>> def areamenu():
>>print 'Square (1)'
>>print 'triangle (2)'
>>print 'rectangle (3)'
>>print 'trapazoid (4)'
>>print 'circle (5)'
>> 
>> def squareacalc():
>>sidelength = input('enter side length: ')
>>print ' the side length is' sidelength ** 2
>> 
>> def displaymenu():
>>print 'please make a selection';
>>print 'Area (1)';
>>choice = input(raw_input('enter selection number'):
>>if (choice == 1):
>>Areamenu():
>> 
>>else:
>>print 'choice' , choice, ' is wrong try again'
>> 
>> def selctiona():
>>Areamenu();
>>choicea = input(raw_input'enter selection');
>>if (choicea == 1):
>>squareacalc()
>> 
>> 
>> 
>> print 'good bye'
>> 
>> I keep getting this error
>> Traceback (most recent call last):
>>  File "", line 1, in 
>>import Area
>>  File "C:\Python27\Area.py", line 10
>>areamenu()
>>   ^
>> SyntaxError: invalid syntax
>> 
>> can anyone tell me what im doing wrong i cant see the problem
>> help would be appreciated
>> 
> What are you using to run the above? I'll guess the interactive window of 
> IDLE. Try reload(Area). Once a module is imported you must reload to import 
> it again. (I am assuming you made changes after the initial error.)
> 
> The above code should give you something like:
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "Script3.py", line 10
>print ' the side length is' sidelength ** 2
> ^
> SyntaxError: invalid syntax
> 
> fix that (do you know what to do?) then you should get a syntax error for 
> line15. Why is there a : at the end of that line?
> then you have 1 more trailing : to deal with.
> then there is a missing )
> then there is a missing (
> 
> Once you fix all the problems then you should see
> good bye
> since that is the only executable code in Area.py other than def statements.
> 
> Suggestion: start with a VERY SIMPLE program and get that working. Then add 
> one new feature at a time.
> 
> -- 
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
> 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error help

2012-03-30 Thread Modulok
On 3/30/12, chris knarvik  wrote:
> Alright i have been trying to right a (relatively) simple to calculate area
> and volume below is my current working code
> def areamenu():
> print 'Square (1)'
> print 'triangle (2)'
> print 'rectangle (3)'
> print 'trapazoid (4)'
> print 'circle (5)'
>
> def squareacalc():
> sidelength = input('enter side length: ')
> print ' the side length is' sidelength ** 2
>
> def displaymenu():
> print 'please make a selection';
> print 'Area (1)';
> choice = input(raw_input('enter selection number'):
> if (choice == 1):
> Areamenu():
>
> else:
> print 'choice' , choice, ' is wrong try again'
>
> def selctiona():
> Areamenu();
> choicea = input(raw_input'enter selection');
> if (choicea == 1):
> squareacalc()
>
>
>
>  print 'good bye'
>
> I keep getting this error
> Traceback (most recent call last):
>   File "", line 1, in 
> import Area
>   File "C:\Python27\Area.py", line 10
> areamenu()
>^
> SyntaxError: invalid syntax
>
> can anyone tell me what im doing wrong i cant see the problem
> help would be appreciated

Chris,

Your code has numerous problems. First, the only lines that should end in a
colon ':' are lines that define something, i.e. class and function signatures,
etc. Your code has them sprinkled in places where they really don't belong. For
instance:

choice = input(raw_input('enter selection number'):  #<-- No.

Additionally, python statements are almost never terminated with a semicolon
';'. Your code has those in random places as well. Python statements *can* be
semicolon terminated, but this should *only* be used if there is more than one
statement per line. (Generally a discouraged practice, unless in the case of a
list comprehensions):

choicea = input(raw_input'enter selection'); #<-- Not needed.

The other problem I see is a lot of mis-matched parentheses. For instance your
code has places where there are two opening parentheses, but only one closing
parenthesis:

choice = input(raw_input('enter selection number'):

Should be:

choice = input(raw_input('enter selection number'))

However, the above line is pretty nasty. It's making an unnecessary function
call. Above, its waiting for user input to the 'input' function, and using the
return value of the 'raw_input' function for that input, which itself is
waiting for user input. i.e. an input waiting for an input. It should instead
be something like this:

choicea = input('enter selection: ')

*If* you decide to use the 'raw_input()' function instead, remember to
type-cast the value that gets entered. By default with 'raw_input()' it is
interpreted as a string and not an integer. Thus, the comparison 'if (choicea
== 1)' wouldn't work with 'raw_input()' expected.

This is a problem as well:

print ' the side length is' sidelength ** 2

The print statement only takes a single argument, or multiple arguments *if*
they are comma separated, e.g:

print ' the side length is', sidelength ** 2

However, this whole thing would be better written using string substitution::

print ' the side length is %s' % (sidelength ** 2)

This is also incorrect:

Areamenu()

Your code defines a function named 'areamenu', not one named 'Areamenu'.
Remember, python is case sEnsItiVe. e.g: Foo() and foo() are different.

Good luck!
-Modulok-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error help

2012-03-30 Thread bob gailer

On 3/30/2012 4:26 PM, chris knarvik wrote:
Alright i have been trying to right a (relatively) simple to calculate 
area and volume below is my current working code


Suggestion: start with a VERY SIMPLE program and get that working. Then 
add one new feature at a time.


Is the following in Area.py? If it is then the traceback could not have 
come from importing this code, because line 10 does not mention areamenu().

In fact areamenu() appears ONLY in line 1, but not by itself!


def areamenu():
print 'Square (1)'
print 'triangle (2)'
print 'rectangle (3)'
print 'trapazoid (4)'
print 'circle (5)'

def squareacalc():
sidelength = input('enter side length: ')
print ' the side length is' sidelength ** 2

def displaymenu():
print 'please make a selection';
print 'Area (1)';
choice = input(raw_input('enter selection number'):
if (choice == 1):
Areamenu():

else:
print 'choice' , choice, ' is wrong try again'

def selctiona():
Areamenu();
choicea = input(raw_input'enter selection');
if (choicea == 1):
squareacalc()



 print 'good bye'

I keep getting this error
Traceback (most recent call last):
  File "", line 1, in 
import Area
  File "C:\Python27\Area.py", line 10
areamenu()
   ^
SyntaxError: invalid syntax

can anyone tell me what im doing wrong i cant see the problem
help would be appreciated

What are you using to run the above? I'll guess the interactive window 
of IDLE. Try reload(Area). Once a module is imported you must reload to 
import it again. (I am assuming you made changes after the initial error.)


The above code should give you something like:
Traceback (most recent call last):
  File "", line 1, in 
  File "Script3.py", line 10
print ' the side length is' sidelength ** 2
 ^
SyntaxError: invalid syntax

fix that (do you know what to do?) then you should get a syntax error 
for line15. Why is there a : at the end of that line?

then you have 1 more trailing : to deal with.
then there is a missing )
then there is a missing (

Once you fix all the problems then you should see
good bye
since that is the only executable code in Area.py other than def statements.

Suggestion: start with a VERY SIMPLE program and get that working. Then 
add one new feature at a time.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Syntax error help

2012-03-30 Thread Evert Rol
> Alright i have been trying to right a (relatively) simple to calculate area 
> and volume below is my current working code
> def areamenu():
> print 'Square (1)'
> print 'triangle (2)'
> print 'rectangle (3)'
> print 'trapazoid (4)'
> print 'circle (5)'
> 
> def squareacalc():
> sidelength = input('enter side length: ')
> print ' the side length is' sidelength ** 2
> 
> def displaymenu():
> print 'please make a selection';
> print 'Area (1)';
> choice = input(raw_input('enter selection number'):

You're missing a closing parenthesis here.

But see comments below.


> if (choice == 1):
> Areamenu():
> 
> else:
> print 'choice' , choice, ' is wrong try again'
> 
> def selctiona():
> Areamenu();
> choicea = input(raw_input'enter selection');

And here you're missing an openening parenthesis.


> if (choicea == 1):
> squareacalc()
> 
> 
> 
>  print 'good bye'
> 
> I keep getting this error
> Traceback (most recent call last):
>   File "", line 1, in 
> import Area
>   File "C:\Python27\Area.py", line 10
> areamenu()
>^
> SyntaxError: invalid syntax
> 
> can anyone tell me what im doing wrong i cant see the problem
> help would be appreciated

A syntax error is often a typing error in the code. In this case, forgotten 
parentheses, but could be forgotten colons or an unclosed string.
The parentheses problem can often be caught by using a good editor: these often 
lightlight when you close a set of parentheses, so you can spot syntax errors 
while you are typing.


There are a number of other things wrong here, though.
Style-wise: Python does not need (and prefers not to have) closing semicolons. 
In addition, there is no need to surround if statements with parentheses: "if 
choice == 1:" is perfectly fine and much more legible.
Perhaps you think (coming from another language): "but it doesn't hurt, and I 
like it this way". But then you're still programming in that other language, 
and just translating to Python; not actually coding in Python.

Also, this is odd, wrong and pretty bad:

   choice = input(raw_input('enter selection number')):

Use either raw_input() (for Python 2.x) or input() (Python 3.x).
It's wrong because you are waiting for input, then use that input as the next 
prompting string for further input. Like this
>>> choice = input(raw_input('enter selection number'))
enter selection number1
12
>>> print choice
2

(the 12 is the 1 I entered before, plus a 2 I just entered as a second entry.)
So just use one function, and the appropriate one for the Python version.
Lastly, choice will be a string, since input() and raw_input() return a string.
In the if-statement, however, you are comparing that string to an integer. 
Python does not do implicit conversion, so you'll have to convert the string to 
an integer first, or compare to a string instead.
(Something similar happens for the sidelength, btw.)
Last thing I see glancing over the code: you define areamenu(), but call 
Areamenu(). Python is case sensitive, so you'd have to call areamenu() instead.


This may be a bit more information than you asked for, but hopefully you don't 
mind.

Good luck,

  Evert




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


[Tutor] Syntax error help

2012-03-30 Thread chris knarvik
Alright i have been trying to right a (relatively) simple to calculate area
and volume below is my current working code
def areamenu():
print 'Square (1)'
print 'triangle (2)'
print 'rectangle (3)'
print 'trapazoid (4)'
print 'circle (5)'

def squareacalc():
sidelength = input('enter side length: ')
print ' the side length is' sidelength ** 2

def displaymenu():
print 'please make a selection';
print 'Area (1)';
choice = input(raw_input('enter selection number'):
if (choice == 1):
Areamenu():

else:
print 'choice' , choice, ' is wrong try again'

def selctiona():
Areamenu();
choicea = input(raw_input'enter selection');
if (choicea == 1):
squareacalc()



 print 'good bye'

I keep getting this error
Traceback (most recent call last):
  File "", line 1, in 
import Area
  File "C:\Python27\Area.py", line 10
areamenu()
   ^
SyntaxError: invalid syntax

can anyone tell me what im doing wrong i cant see the problem
help would be appreciated
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error with if statement

2011-08-24 Thread Andre Engels
On Wed, Aug 24, 2011 at 7:40 PM, Ray Parrish  wrote:

> Hello,
>
> I haven't been programming for a while and today I am working on something
> and have encountered an error I cannot figure out.
>
> Here is my code:
>
>  thisFile = column[6]
>  if thisFile == "/Images/My%20Face.JPG"
>   CallCount += 1
>   print CallCount
>
> And here is the error message:
>
> ray@RaysComputer:~$ python /home/ray/EmailCount/**CountEmails.py
>  File "/home/ray/EmailCount/**CountEmails.py", line 41
>if thisFile == "/Images/My%20Face.JPG"
>  ^
> SyntaxError: invalid syntax
>
> Any help you can be will be much appreciated.
>

There has to be a : at the end of an if statement, or more generally, any
statement that is to be followed by an indented block.

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Syntax error with if statement

2011-08-24 Thread Ray Parrish

Hello,

I haven't been programming for a while and today I 
am working on something and have encountered an 
error I cannot figure out.


Here is my code:

  thisFile = column[6]
  if thisFile == "/Images/My%20Face.JPG"
   CallCount += 1
   print CallCount

And here is the error message:

ray@RaysComputer:~$ python 
/home/ray/EmailCount/CountEmails.py

  File "/home/ray/EmailCount/CountEmails.py", line 41
if thisFile == "/Images/My%20Face.JPG"
  ^
SyntaxError: invalid syntax

Any help you can be will be much appreciated.

Later, Ray Parrish

--
The Unknown Lead Player, Ray Parrish
http://www.facebook.com/pages/The-Unknown-Lead-Player/123388551041130?sk=wall
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] syntax error that i cant spot!

2011-01-05 Thread Noah Hall
>
> "Please" and "Thank you" are rude? Oh my, have you lived a sheltered life
> :)
>

Nej, it was your condescension that I found rude. Also, you did it again,
perhaps on purpose though.. ;)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-05 Thread Steven D'Aprano

Noah Hall wrote:

Please quote enough of the previous message to establish context -- when
you are replying to the message, it is fresh in your mind. When others read
your reply (possibly days later like I'm doing now), the context is anything
but clear and your message comes across  as merely mysterious and obscure.



Certainly. In fact, it was an error in that message - I had deleted
accidentally that which I had quoted. Please be aware, however, rudeness
does nothing for you.



"Please" and "Thank you" are rude? Oh my, have you lived a sheltered life :)


--
Steven

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


Re: [Tutor] syntax error that i cant spot!

2011-01-05 Thread Noah Hall
>
> Please quote enough of the previous message to establish context -- when
> you are replying to the message, it is fresh in your mind. When others read
> your reply (possibly days later like I'm doing now), the context is anything
> but clear and your message comes across  as merely mysterious and obscure.


Certainly. In fact, it was an error in that message - I had deleted
accidentally that which I had quoted. Please be aware, however, rudeness
does nothing for you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-05 Thread Steven D'Aprano

Noah Hall wrote:

He has no classes in there. Therefore, there is no place it should be in
this code. Please remember this is Python, and not Java nor anything else.

[...]

It just makes life easier.


Oh the irony... talking about making life easier, who are you talking 
to? What about?


Please quote enough of the previous message to establish context -- when 
you are replying to the message, it is fresh in your mind. When others 
read your reply (possibly days later like I'm doing now), the context is 
anything but clear and your message comes across as merely mysterious 
and obscure.



Thank you.




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


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Wayne Werner
On Sun, Jan 2, 2011 at 9:52 AM, Alan Gauld wrote:

> "Corey Richardson"  wrote
>
>  On Sat, Jan 1, 2011 at 9:10 PM, Alan Gauld 
>>> wrote:
>>>
 Why avoidCamelCase? I actually prefer it to using_non_camel_case

>>>
>>> Python appears to use camelCase more than not.
>>>
>>>
>> I tend to disagree with that. In the stdlib, as well as the builtins,
>> many, many methods are alllowercase, for example str.isdigit() or
>> socket.gethostname().
>>
>
> Which should, according to PEP8, be get_hostname()(*) and
> is_digit()...
>
> The stdlib is a mess of inconsistency. I assume that's why PEP8
> seems to get more attention these days - it's been around for ages.
> Some modules use CamelCase, some use underscores and
> some just use long lowercase names (the worst option! - well
> apart from all uppercase like COBOL...!)
>

Well, PEP8 does suggest that the preference is 1) lowercase names unless
readability suffers, such as in goallist or something that can be improved,
then 2) goal_list is preferred over goalList, unless 3) existing code uses
theOtherWay.

Personally I feel lowercase_with_underscores to be more readable than
lowercaseWithoutUnderscores, although since I took that (required) Java
class my junior year, I'm used to
typingIncrediblyLongNamesThatAreRidiculouslyVerboseTellingYouEverythingThatTheClassOrFunctionMayOrMayNotDo,
in that style of case. I am firmly convinced that Java is the reason IDEs
with really good auto complete were developed ;)

I try to code according to PEP8, and write all my functions/variables using
onlylowercase except when_i_cant_tell_what_that_word_is. And of course I try
to make my variables as short as possible, but no shorter :)

-lowercasefully,
wayne_werner


>
> (*)hostname could be host_name I guess but Unix tradition
> spells it as one word so I've followed that convention...
>
> Alan G
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Ken Green
I generally prefer Camel Case as easily to use as it would be more 
difficult for me as a touch typist to hunt and peck for the underscore.


Ken

On 01/02/2011 09:40 AM, Brett Ritter wrote:

On Sat, Jan 1, 2011 at 9:10 PM, Alan Gauld  wrote:

Why avoidCamelCase? I actually prefer it to using_non_camel_case

The readability is an often argued topic - I myself find the space of
names_in_underscores to be more readable (words are distinct), but I
try to follow the common conventions of the languages I'm using, and
Python appears to use camelCase more than not.


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


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Alan Gauld

"Corey Richardson"  wrote

On Sat, Jan 1, 2011 at 9:10 PM, Alan Gauld 
 wrote:

Why avoidCamelCase? I actually prefer it to using_non_camel_case


Python appears to use camelCase more than not.



I tend to disagree with that. In the stdlib, as well as the 
builtins,

many, many methods are alllowercase, for example str.isdigit() or
socket.gethostname().


Which should, according to PEP8, be get_hostname()(*) and
is_digit()...

The stdlib is a mess of inconsistency. I assume that's why PEP8
seems to get more attention these days - it's been around for ages.
Some modules use CamelCase, some use underscores and
some just use long lowercase names (the worst option! - well
apart from all uppercase like COBOL...!)

(*)hostname could be host_name I guess but Unix tradition
spells it as one word so I've followed that convention...

Alan G 



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


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Corey Richardson
On 01/02/2011 09:40 AM, Brett Ritter wrote:
> On Sat, Jan 1, 2011 at 9:10 PM, Alan Gauld  wrote:
>> Why avoidCamelCase? I actually prefer it to using_non_camel_case
> 
> The readability is an often argued topic - I myself find the space of
> names_in_underscores to be more readable (words are distinct), but I
> try to follow the common conventions of the languages I'm using, and
> Python appears to use camelCase more than not.
> 

I tend to disagree with that. In the stdlib, as well as the builtins,
many, many methods are alllowercase, for example str.isdigit() or
socket.gethostname().
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Hugo Arts
On Sun, Jan 2, 2011 at 3:40 PM, Brett Ritter  wrote:
> On Sat, Jan 1, 2011 at 9:10 PM, Alan Gauld  wrote:
>> Why avoidCamelCase? I actually prefer it to using_non_camel_case
>
> The readability is an often argued topic - I myself find the space of
> names_in_underscores to be more readable (words are distinct), but I
> try to follow the common conventions of the languages I'm using, and
> Python appears to use camelCase more than not.
>

according to PEP 8, python doesn't use camelCase (mixedCase, as they
call it) at all. Or shouldn't, in any case. No pun intended.

For classnames you should use CapWords. The only difference with
camelCase is the initial character. variable and function names should
use lower_case_with_underscores.

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


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Brett Ritter
On Sat, Jan 1, 2011 at 9:10 PM, Alan Gauld  wrote:
> Why avoidCamelCase? I actually prefer it to using_non_camel_case

The readability is an often argued topic - I myself find the space of
names_in_underscores to be more readable (words are distinct), but I
try to follow the common conventions of the languages I'm using, and
Python appears to use camelCase more than not.

-- 
Brett Ritter / SwiftOne
swift...@swiftone.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Noah Hall
He has no classes in there. Therefore, there is no place it should be in
this code. Please remember this is Python, and not Java nor anything else.
To quote directly from PEP 8, in regards to functions and variables,
 "should be lowercase, with words separated by underscoresas necessary to
improve readability.". Notice the word "readability" there ;). It's not a
big issue when you're working by yourself, but when working with multiple
people, or asking for help (like the OP here), you should stick to the
conventions of that language. it saves you time when you're trying to read
other people's code, it saves others' time when they try to read your code
and it saves time when they try and fix your code. It just makes life
easier.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-02 Thread Alan Gauld


"Noah Hall"  wrote

It's part of the Python naming conventions laid out by PEP 8. Have a 
read

here - http://www.python.org/dev/peps/pep-0008/.


I'm quite familiar with PEP8 - although I disagree with quite a lot of 
it too!
But PEP 8 is about consistency of style not "readability" which was 
what

was claimed about CamelCase. I'm not aware of any studies which
show CamelCase as being significantly less readable than
underline_seperators.

And even PEP8 encourages the use of CamelCase for classes or where
it is already being used. Where it refers to readability in the use of
underscores its referring to using the underscores to add readability
ie bank_account rather than bankaccount, not in contrast to 
BankAccount.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Noah Hall
It's part of the Python naming conventions laid out by PEP 8. Have a read
here - http://www.python.org/dev/peps/pep-0008/.

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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Alan Gauld


"Noah Hall"  wrote


By the way, for readability, tryToavoidCamelCase.


Why avoidCamelCase? 
I actually prefer it to using_non_camel_case


But it's been the standard in OOP languages since 
at least Smalltalk 80 (ie 1980) so I guess I'm just used to it...


Alan G.

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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Ken Green
He had no space between the plus sign and the name value and that threw 
me.  I am so used to using a space before or after the plus sign.


Ken

On 01/01/2011 02:46 PM, bob gailer wrote:

On 1/1/2011 2:28 PM, Ken Green wrote:
I am caught off guard but what is the purpose of the plus sign?  I 
don't recall seeing it used like that.


I just tried to look that up in the Python Manuals. No success! Where 
is it hiding?


>>> a = 'a'
>>> b = 'b'
>>> c = a + b
>>> print c
ab

Now you can recall seeing it.


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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Noah Hall
>
> > I am caught off guard but what is the purpose of the plus sign?  I don't
> recall seeing it used like that.
>

The + sign there is used for concating two strings together, for example -

output = 'foo' + 'bar'

Will give the variable output the value of the characters 'foobar'. This
also works with mixed values of variables holding strings and raw strings,
for example -

foo = 'foo'
output = foo + 'bar'

Which gives the same output as my previous example.

To OP:

I would not use the method you have used, but rather use string formatting,
so I would use on line 10 -

print 'Well, %s, I am thinking of a number between 1 & 20.' % (myName)

And on line 30 (which won't need the str(guessesTaken) on line 29) -

print 'Good job, %s! You guessed the number in %d guesses!' % (myName,
guessesTaken)

And then finally on line 34 -

print 'Nope. The number I was thinking of was %d' % (number)


By the way, for readability, tryToavoidCamelCase.
I also recommend you look into functions, classes, and exceptions - this
example is a good one with a lot of room to grow :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread bob gailer

On 1/1/2011 2:28 PM, Ken Green wrote:

I am caught off guard but what is the purpose of the plus sign?  I
don't recall seeing it used like that.


I just tried to look that up in the Python Manuals. No success! Where is 
it hiding?


*** OOPS just found it in section 6.6 Sequence Types
s + t the concatenation of s and t


a = 'a'
b = 'b'
c = a + b
print c

ab

Now you can recall seeing it.

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread bob gailer

On 1/1/2011 2:28 PM, Ken Green wrote:
I am caught off guard but what is the purpose of the plus sign?  I 
don't recall seeing it used like that.


I just tried to look that up in the Python Manuals. No success! Where is 
it hiding?


>>> a = 'a'
>>> b = 'b'
>>> c = a + b
>>> print c
ab

Now you can recall seeing it.

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Corey Richardson

On 01/01/2011 02:28 PM, Ken Green wrote:

I am caught off guard but what is the purpose of the plus sign? I don't
recall seeing it used like that.

Ken

On 01/01/2011 12:11 PM, Abhijeet Rastogi wrote:

You missed a "+" after myName on line 30.

On Sat, Jan 1, 2011 at 10:32 PM, pete mailto:psmo...@live.com>> wrote:

Hi,
Please help just starting out and have come up with the following
code to create a simple guessing game.

on line 30 print good job etc i get a syntax error! sure it's
simple but i've looked for ages and cant spot it!

Regards
Pete

_



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


The + operator in this case concatenates, or joins, two strings.
"Hello, " + "World" == "Hello, World"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Ken Green
I am caught off guard but what is the purpose of the plus sign?  I don't 
recall seeing it used like that.


Ken

On 01/01/2011 12:11 PM, Abhijeet Rastogi wrote:

You missed a "+" after myName on line 30.

On Sat, Jan 1, 2011 at 10:32 PM, pete > wrote:


Hi,
Please help just starting out and have come up with the following
code to create a simple guessing game.

on line 30 print good job etc i get a syntax error! sure it's
simple but i've looked for ages and cant spot it!

Regards
Pete

_



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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread David Hutto
You also can place:

else:
print " this is not a number"



And:

if guess == number:
break

if guess == number:
guessesTaken = str(guessesTaken)
print 'Good job, ' + myName + "! You guessed the number in " +
guessesTaken + ' guesses!'

which could be combined.


 if guess == number:
guessesTaken = str(guessesTaken)
print 'Good job, ' + myName + "! You guessed the number in " +
guessesTaken + ' guesses!'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Knacktus

Am 01.01.2011 18:02, schrieb pete:

Hi,
Please help just starting out and have come up with the following code
to create a simple guessing game.

on line 30 print good job etc i get a syntax error! sure it's simple but
i've looked for ages and cant spot it!

There's a + missing after myName

Also, I would use the same type of quotation marks. Not mixing '' and "".



Regards
Pete



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


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


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread David Hutto
On Sat, Jan 1, 2011 at 12:02 PM, pete  wrote:
> Hi,
> Please help just starting out and have come up with the following code to
> create a simple guessing game.
>
> on line 30 print good job etc i get a syntax error! sure it's simple but
> i've looked for ages and cant spot it!
>
> Regards
> Pete

 print 'Good job, ' + myName + "! You guessed the number in " +
guessesTaken + ' guesses!'


you forgot to place a plus in between myName and "! You guessed the number in ".
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error that i cant spot!

2011-01-01 Thread Abhijeet Rastogi
You missed a "+" after myName on line 30.

On Sat, Jan 1, 2011 at 10:32 PM, pete  wrote:

> Hi,
> Please help just starting out and have come up with the following code to
> create a simple guessing game.
>
> on line 30 print good job etc i get a syntax error! sure it's simple but
> i've looked for ages and cant spot it!
>
> Regards
> Pete
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Abhijeet Rastogi (shadyabhi)
http://www.google.com/profiles/abhijeet.1989
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] syntax error that i cant spot!

2011-01-01 Thread pete

Hi,
Please help just starting out and have come up with the following code 
to create a simple guessing game.


on line 30 print good job etc i get a syntax error! sure it's simple but 
i've looked for ages and cant spot it!


Regards
Pete
# guess the number game
import random

guessesTaken = 0

print 'Hello what is your name?'
myName = raw_input()

number = random.randint(1, 20)
print 'Well, ' + myName + ', I am thinking of a number between 1 & 20.'

while guessesTaken < 6:
print 'Take a guess.' # 4 spaces infront of print
guess = raw_input()
guess = int(guess)

guessesTaken = guessesTaken +1

if guess < number:
print 'Your guess is too low,' # 8 spaces...

if guess > number:
print 'Your guess is too high.'

if guess == number:
break

if guess ==number:
guessesTaken = str(guessesTaken)
print 'Good job, ' +myName "! You guessed the number in " + guessesTaken + ' guesses!'

if guess !=number:
number = str(number)
print 'Nope. The number I was thinking of was ' + number

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


Re: [Tutor] Syntax Error Messages

2010-10-22 Thread David Hutto
What my buddy pal is saying, is that you should start at the
beginning. I first downloaded x version of python to x operating
system, then I tried this tutorial with these explicit
modules/requirements(which I may or not have) then progress to the
smaller aspects, like this won't iterate, or that doesn't coagulate
with this, etc.

After asking a few initially awkwardly ignorant questions, you might
know as much as me...How to use the basic library, with, a few
exceptions in personal taste.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Error Messages

2010-10-22 Thread Steven D'Aprano
On Sat, 23 Oct 2010 05:49:07 am Terry Green wrote:

> I found this script when looking at the CVS module and loaded
> It into PyScripter, but get: Syntax Error: Invalid Syntax
> Cannot figure out why and Googleing for help doesn't help
>
> Any ideas?

No, no, don't show us the actual error that you got! I LOVE guessing 
games.



Nah, I'm actually lying, I hate guessing games.

Please COPY AND PASTE (do NOT retype, summarise, paraphrase or write out 
from memory) the EXACT error message you get. It will include the line 
causing the syntax error, like this:

>>> print "abc
  File "", line 1
print "abc
 ^
SyntaxError: EOL while scanning string literal


We need to see the entire message, not just a vague description that 
it's a syntax error.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Error Messages

2010-10-22 Thread Hugo Arts
On Fri, Oct 22, 2010 at 8:49 PM, Terry Green  wrote:
> Am new to Python, and having difficulty with Error Messages
>
> I ‘m using Python 3.1
>
> And PyScripter as my editor
>
>
>
> I want to process a comma delimited file one line at a time and
> Interact with the fields within each line.
> I found this script when looking at the CVS module and loaded
> It into PyScripter, but get: Syntax Error: Invalid Syntax
> Cannot figure out why and Googleing for help doesn’t help
>
> Any ideas?
>
> import csv, sys
>
> filename = "some.csv"
>
> reader = csv.reader(open(filename, "rb"))
>
> try:
>
>     for row in reader:
>
>     print (row)
>
> except csv.Error, e:
>
>     sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
>
>
> thanks,
> Terry Green
>

You should have gotten more information than just that error. The
offending line should also be printed, along with an estimate of where
exactly the error occurred. Please copy-paste *all* information the
traceback gives you, unless it is too long (a good rule of thumb is
"would *I* read all this just to help some stranger out?"). The more
information we have to work with, the better.

In any case, that python code was written for python 2.x, not 3.x. If
you change "except csv.Error, e:" to "except csv.Error as e:" it
should work.

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


[Tutor] Syntax Error Messages

2010-10-22 Thread Terry Green
Am new to Python, and having difficulty with Error Messages

I 'm using Python 3.1

And PyScripter as my editor

 

I want to process a comma delimited file one line at a time and

Interact with the fields within each line.

I found this script when looking at the CVS module and loaded

It into PyScripter, but get: Syntax Error: Invalid Syntax

Cannot figure out why and Googleing for help doesn't help

Any ideas?

 

 

import csv, sys

filename = "some.csv"

reader = csv.reader(open(filename, "rb"))

try:

for row in reader:

print (row)

except csv.Error, e:

sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))

 

 

 

thanks,

 

Terry Green

 

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


Re: [Tutor] syntax error

2009-06-28 Thread Alan Gauld
"Christopher Altieri"  wrote 

loaded python 3 and 3.1 several times on vista. tried first 
command: print "hello world' but keep getting syntax error. 
what am I doing wrong?


Using Python 3 to learn Python! :-)

Seriously, You would be better downgrading to Python 2.6 
to learn because v3 has introduced several new concepts 
(not just print() ) that are not covered in most tutorials.  
Once you understand Python 2.6 you will be in a better 
position to understamd v3s new features, and probably 
by then most tutorials will have caught up.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

And for V3:

http://www.alan-g.me.uk/l2p/

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error

2009-06-25 Thread Christian Witts

Christopher Altieri wrote:
loaded python 3 and 3.1 several times on vista. tried first command: 
print "hello world' but keep getting syntax error. what am I doing wrong?





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  
Python 3.0+ print has been changed to a function so you need to do 
print("Hello World!")


--
Kind Regards,
Christian Witts

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] syntax error

2009-06-25 Thread Christopher Altieri
loaded python 3 and 3.1 several times on vista. tried first command: print 
"hello world' but keep getting syntax error. what am I doing wrong?


  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Error First Example

2009-06-11 Thread Kent Johnson
On Wed, Jun 10, 2009 at 10:02 PM, Randy Trahan wrote:

> First, I am suppose to put this in the script mode vs the IDLE mode correct?
> He failed to mention where..

Generally the "Python Shell" window is for interactive exploration and
to see the results of your scripts. To type in a complete program use
a new editing window (File / New).

You might find this tour of IDLE to be helpful:
http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/

> Also, I get a syntax error at "input"? Since its my first day/hour I don't
> know how to debug and its typed in exactly as he wrote it...

It's very helpful to us if you copy and paste the exact error text,
including the traceback, when you ask for help with errors.

Welcome to Python!
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Error First Example

2009-06-10 Thread Lie Ryan
Randy Trahan wrote:
> Hi,
> Just opened the book Python Programming, Second Edition by Michael
> Dawson and have my first question. Instead of the usual "Hello World" as
> the first example he asked to type this:
>  
> print "Game Over"
> raw input("\n\nPress the enter key to exit.")
>  
> First, I am suppose to put this in the script mode vs the IDLE mode
> correct? He failed to mention where..

There are a few subtle differences between running in script mode and
interactive mode; notably that you can print the repr of an object
without a print statement/function in interactive mode. However for this
particular example, the difference are not significant.

> Also, I get a syntax error at "input"? Since its my first day/hour I
> don't know how to debug and its typed in exactly as he wrote it...



> Finally, I'm running Python 2.6 on Vista. It loaded but the book did not
> mention Vista it only went up to XP. Is that ok?
Python supports Vista; maybe the book is a bit old.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Error First Example

2009-06-10 Thread Wayne
On Wed, Jun 10, 2009 at 9:12 PM, bob gailer  wrote:

> Randy Trahan wrote:
>
>>  First, I am suppose to put this in the script mode vs the IDLE mode
>> correct? He failed to mention where..
>
>
It really doesn't matter - although presumably he meant you to write a
script instead of in the shell/interactive interpreter (the prompt starting
>>> )


>   Also, I get a syntax error at "input"? Since its my first day/hour I
>> don't know how to debug and its typed in exactly as he wrote it...
>>  Finally, I'm running Python 2.6 on Vista. It loaded but the book did not
>> mention Vista it only went up to XP. Is that ok?
>>
>
Python works(ed?) fine on my computer when I ran Vista. As long as you keep
to the 2.XX series of Python you shouldn't have too much trouble picking up
python - it's really only if you start switching to Python 3 that you'll
have a problem - specifically a lot of statements have turned into
functions... but that's a discussion for a different day :)

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax Error First Example

2009-06-10 Thread bob gailer

Randy Trahan wrote:

Hi,
Just opened the book Python Programming, Second Edition by Michael 
Dawson and have my first question. Instead of the usual "Hello World" 
as the first example he asked to type this:
 
print "Game Over"

raw input("\n\nPress the enter key to exit.")


Try raw_input("\n\nPress the enter key to exit.")
 
First, I am suppose to put this in the script mode vs the IDLE mode 
correct? He failed to mention where..
 
Also, I get a syntax error at "input"? Since its my first day/hour I 
don't know how to debug and its typed in exactly as he wrote it...
 
Finally, I'm running Python 2.6 on Vista. It loaded but the book did 
not mention Vista it only went up to XP. Is that ok?
 
Any help would be appreciated.


--
Randy Trahan
Owner, BullDog Computer Services, LLC
478-396-2516


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  



--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Syntax Error First Example

2009-06-10 Thread Randy Trahan
Hi,
Just opened the book Python Programming, Second Edition by Michael Dawson
and have my first question. Instead of the usual "Hello World" as the first
example he asked to type this:

print "Game Over"
raw input("\n\nPress the enter key to exit.")

First, I am suppose to put this in the script mode vs the IDLE mode correct?
He failed to mention where..

Also, I get a syntax error at "input"? Since its my first day/hour I don't
know how to debug and its typed in exactly as he wrote it...

Finally, I'm running Python 2.6 on Vista. It loaded but the book did not
mention Vista it only went up to XP. Is that ok?

Any help would be appreciated.

-- 
Randy Trahan
Owner, BullDog Computer Services, LLC
478-396-2516
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error

2009-03-23 Thread John Jenkinson
I am using Python 2.4.1.  I am using the IDLE process, and I was not saving
as ".py".  Thank you, everyone, for your continued help.

On Mon, Mar 23, 2009 at 3:35 AM, Alan Gauld wrote:

>
> "John Jenkinson"  wrote
>
>  I am trying to write a program that displays the string expression "Game
>> Over", in a console window that remains open.
>>
>> print "Game Over"
>> raw input("\n\nPress the enter key to exit.")
>>
>> I dont understand what is supposed to happen if the code were to be
>> correct.  Would a separate console be displayed with the text "Game Over",
>> or would I see the output in the Interactive Mode window?
>>
>
> This would display the Game Over message followed by the
> Press enter key message in the window wghere the program was executing
> and then wait for the user to hit the key before closing the window..
>
> The problem you have is that I suspect you are using IDLE or Pythonwin
> to write the code. These tools are development tools and not what you
> would normally use to run the program. They do not display their output
> in a window but rather do so in the interactive shell within the tool.
>
> To see the program act as the auithor intended save the file with a
> .py extension and then double click on it in Windows Explorer
> (assuming you are on Windows!). This will open a Command window
> with the program running inside.
>
> Finally, to select error messages for posting you need to do something
> similar.
> Start a command window (Start->Run, type CMD, hit OK). At the OS
> command prompt type python and then drag your program file onto the window.
> This will run the program and leave the error message on screen. You can
> then
> use the control menu(click on the window icon) Edit->Mark, Edit->Copy to
> select the text and copy it to the clipboard so that you can paste it into
> a
> mail message.
>
> HTH,
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error

2009-03-23 Thread Alan Gauld


"John Jenkinson"  wrote

I am trying to write a program that displays the string expression 
"Game

Over", in a console window that remains open.

print "Game Over"
raw input("\n\nPress the enter key to exit.")

I dont understand what is supposed to happen if the code were to be
correct.  Would a separate console be displayed with the text "Game 
Over",

or would I see the output in the Interactive Mode window?


This would display the Game Over message followed by the
Press enter key message in the window wghere the program was executing
and then wait for the user to hit the key before closing the window..

The problem you have is that I suspect you are using IDLE or Pythonwin
to write the code. These tools are development tools and not what you
would normally use to run the program. They do not display their 
output

in a window but rather do so in the interactive shell within the tool.

To see the program act as the auithor intended save the file with a
.py extension and then double click on it in Windows Explorer
(assuming you are on Windows!). This will open a Command window
with the program running inside.

Finally, to select error messages for posting you need to do something 
similar.

Start a command window (Start->Run, type CMD, hit OK). At the OS
command prompt type python and then drag your program file onto the 
window.
This will run the program and leave the error message on screen. You 
can then
use the control menu(click on the window icon) Edit->Mark, Edit->Copy 
to
select the text and copy it to the clipboard so that you can paste it 
into a

mail message.

HTH,


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





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax error

2009-03-22 Thread John Jenkinson
I understand.  I am following a tutorial that has a typo.

Quoting from the text:

The last line of the program:
raw input("\n\nPress the enter key to exit.")

I enjoyed your intuitive explanation, thank you.

On Sun, Mar 22, 2009 at 11:30 PM, Marc Tompkins wrote:

>  On Sun, Mar 22, 2009 at 8:35 PM, John Jenkinson  > wrote:
>
>> I am trying to write a program that displays the string expression "Game
>> Over", in a console window that remains open.
>>
>> my code is as follows:
>>
>> # Game Over console window
>>
>> print "Game Over"
>> raw input("\n\nPress the enter key to exit.")
>>
>
> Assuming that you've posted exactly what's in your program, the problem is
> "raw input()" (which would mean 'execute a statement called raw, with an
> input() function following it') instead of "raw_input()".  Since there isn't
> a built-in statement called "raw", you get the syntax error.
>
> Spelling counts.
>
> --
> www.fsrtechnologies.com
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


  1   2   >