Re: [Tutor] challenge-chapter 2

2013-05-24 Thread Steven D'Aprano

On 25/05/13 09:41, bob gailer wrote:

On 5/22/2013 1:02 AM, Andrew Triplett wrote:

... illegal variable names ...

That is a very poor description. Something can either be used as a variable 
name or not.

abc can be used as a variable name, if can't.


But it can be used as a variable name in some languages. "if" is at least 
*potentially* a variable name, in the sense that somebody might try to use it as a name.



I defy you to give me a variable name that is illegal! Anything you attempt to 
give in that category is not a variable name.


While you are strictly correct, you are missing the point of the exercise, 
which is to distinguish between strings which can be used as variable names:

pedant
variable
constant
this_is_not_a_variable
pi
tau
alpha1234


and those that can't:

1234alpha
*$%^
for
return
this-is-a-variable


A better name for this is "identifier" rather than "variable name", and Python 
3 defines a string method to test whether or not something is a valid identifier:

http://docs.python.org/3/library/stdtypes.html#str.isidentifier


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


Re: [Tutor] challenge-chapter 2

2013-05-24 Thread bob gailer

On 5/22/2013 1:02 AM, Andrew Triplett wrote:

... illegal variable names ...
That is a very poor description. Something can either be used as a 
variable name or not.


abc can be used as a variable name, if can't.

I defy you to give me a variable name that is illegal! Anything you 
attempt to give in that category is not a variable name.


--
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] challenge-chapter 2

2013-05-22 Thread Evans Anyokwu
Hi Andrew,

I'm sure the exercises at the end of the each chapters are there for you to
attempt. Asking for help here without attempting it is not the best way to
learn.
If however, you've tried something - and it didn't work, by all means ask
for help.

In the mean time show us what you have so far.


Good luck,
Evans


On Wed, May 22, 2013 at 6:02 AM, Andrew Triplett wrote:

> I am on chapter two for Python Programming working on the challenges and
> the question is:
>
> 1. Create a list of legal and illegal variable names. Describe why each is
> either legal or illegal. Next, create a list of "good" and "bad" legal
> variable names. Describe why each is either a good or bad choice for a
> variable name.
>
> Can you help me solve this problem?
>
> ___
> 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] challenge-chapter 2

2013-05-22 Thread Matthew Ngaha
On Wed, May 22, 2013 at 6:02 AM, Andrew Triplett  wrote:
> I am on chapter two for Python Programming working on the challenges and the
> question is:
>
> 1. Create a list of legal and illegal variable names. Describe why each is
> either legal or illegal. Next, create a list of "good" and "bad" legal
> variable names. Describe why each is either a good or bad choice for a
> variable name.
>

The title is a bit ambigious. Just incase anyone likes the sound of
the challenge, the book is:
Python Programming For The Absolute Beginner
i also used it and would recommend it to anyone trying to learn Python
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] challenge-chapter 2

2013-05-22 Thread Peter Otten
Andrew Triplett wrote:

> I am on chapter two for Python Programming working on the challenges and
> the question is:
> 
> 1. Create a list of legal and illegal variable names. Describe why each is
> either legal or illegal. Next, create a list of "good" and "bad" legal
> variable names. Describe why each is either a good or bad choice for a
> variable name.
> 
> Can you help me solve this problem?

i
n
foo
1timepad
with
__
_name
__name
row1
row2
row3
question
length
x
bottles
number_of_bottles
number_of_bottles_of_beer_on_the_wall
seperate_concerns
next_KindOfQuestion
it's_about_time
Animal
animal
ANIMAL
HttpServer
HTTPServer
bin2hex
bin_to_hex
childs
intNumber
strValue

So here's your lists, but they got totally mixed up. Also, while it's easy 
to separate the legal from the illegal names (by typing them into the 
interpreter) the distinction between good and bad is not so clear-cut.
You really have to think about it and form an opinion. Write it down in a 
sentence or two and post it here.

Hint: Often a name may even be good or bad depending on the context.
For example

for x, y in points:
r = math.sqrt(x*x + y*y)
print x, y, "-->", r

Here x is a fine name because if follows a well-known mathematical 
convention...

with open(datafile, "rb") as f:
x = pickle.load(f)

...whereas this x leaves you totally clueless about what x could contain.


Another hint: One criterium to decide whether a name is "good" is its 
compliance with PEP 8 



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


[Tutor] challenge-chapter 2

2013-05-21 Thread Andrew Triplett
I am on chapter two for Python Programming working on the challenges and the 
question is:

1. Create a list of legal and illegal variable names. Describe why each is 
either legal or illegal. Next, create a list of "good" and "bad" legal variable 
names. Describe why each is either a good or bad choice for a variable name.

Can you help me solve this problem?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor