[Tutor] Jion list!

2013-05-24 Thread jiangtao sheng
Hi,i am JiangtaoSheng!!
___
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 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] Parentheses and tuples [was Re: Fwd: Difference between types]

2013-05-24 Thread Devin Jeanpierre
On Fri, May 24, 2013 at 10:35 PM, Steven D'Aprano  wrote:
> So single-item tuples are not special. They just follow the rules for
> multiple-item tuples, except that you only have item.

And except that the trailing comma is not optional. So, they are
special after all.

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


[Tutor] Parentheses and tuples [was Re: Fwd: Difference between types]

2013-05-24 Thread Steven D'Aprano

On 25/05/13 04:53, Albert-Jan Roskam wrote:


Why do I need to use a trailing comma to create a singleton tuple? Without a comma it 
seems to mean "parenthesized single object", ie the parentheses are basically 
not there.



Because round brackets are also used for grouping. You can group any expression:

z = (x+1)*y


Even an expression consisting of a single element:

z = (x+1)*(y)


That might not be a sensible thing to do, but it's not worth special-casing the 
parser to reject parentheses in this case. Now bring in tuples. Tuples are 
created by the comma operator, NOT the parentheses:

a = 23, 42, None

creates a tuple. At least one comma is necessary to distinguish an element from 
a tuple of one element:

a = 23  # a is the int 23
a = 23,  # a is a one-item tuple containing 23

Sometimes you use round brackets to group the tuple item, either because you 
need to change the precedence:

a = 23, (2, 4, 8), None

groups the three elements 2, 4, 8 into a tuple, which in turn is in a tuple:

print a
=> (23, (2, 4, 8), None)


Or we use round brackets to make a tuple just because it looks better, and 
matches the display of them:

a = (23, 42, None)
print a
=> (23, 42, None)

But make no mistake: it is the comma, not the brackets, that makes the tuple.

So single-item tuples are not special. They just follow the rules for 
multiple-item tuples, except that you only have item. That does leave the 
question of how to specify an empty tuple. And that is special:

a = ()

however it does match the display of empty tuples, and looks rather similar to 
empty lists [] and empty dicts {}.



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


Re: [Tutor] keyboard interrupt

2013-05-24 Thread eryksun
On Fri, May 24, 2013 at 10:19 PM, Steven D'Aprano  wrote:
>
> You can edit *other* people's questions and answers??!??!??
>
> What. The. Hell.

This should be done sparingly for answers. But it's very common for
questions since inexperienced users almost always get the markdown
wrong.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] keyboard interrupt

2013-05-24 Thread Robert Sjoblom
On 25 May 2013 04:19, Steven D'Aprano  wrote:
> You can edit *other* people's questions and answers??!??!??
>
> What. The. Hell.

Yes; I think that the idea is that it allows people to fix spelling
errors and/or reference mistakes, or maybe add things to clarify
something that the answer glossed over to begin with. I'm not entirely
sure how it works other than that you can edit answers and it's then
moderated by someone -- maybe the person who initially wrote the
answer? Or maybe you get moderator rights when reach a certain score.
--
best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] keyboard interrupt

2013-05-24 Thread Steven D'Aprano

On 25/05/13 01:11, Marc Tompkins wrote:


I love, love, love StackOverflow (and the whole StackExchange ecosystem),
but it's unfortunately susceptible to being gamed.  Anyone can edit a
question (or an answer), and if the edit is allowed to stand the editor
gets 2 points.



You can edit *other* people's questions and answers??!??!??

What. The. Hell.



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


Re: [Tutor] making a random list, then naming it

2013-05-24 Thread eryksun
On Fri, May 24, 2013 at 9:10 PM, Dave Angel  wrote:
>
> Is lists[(3,8)]  really so much harder to type than
> list_3_8  ?

Since a comma creates a tuple, in this context you can just use
lists[3,8] to save a couple more keystrokes.

>>> from random import Random
>>> randint = Random(42).randint

>>> lists = {}
>>> lists[3,8] = [randint(0,8) for i in range(3)]
>>> lists
{(3, 8): [1, 0, 4]}
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making a random list, then naming it

2013-05-24 Thread Dave Angel

On 05/24/2013 09:35 PM, Jim Mooney wrote:

On 24 May 2013 18:10, Dave Angel  wrote:


Is lists[(3,8)]  really so much harder to type than
 list_3_8  ?



You have a point. I hate underlines - my finger always misses them.
Keyboards were not designed for programming ;')

Anyway, I just thought I'd try exec, but it's giving me fits putting it in
a function so I can do multiple lists. A dictionary looks more manageable.

Jim



Just to save you further frustration, CPython compiles a function in 
such a way that adding new local identifiers to the function is 
effectively impossible.  The compiler decided long before the function 
is run how many locals there are, and what they're called.


So some sneaky tricks that work at global level won't work inside a 
function.


Other Python implementations may have other gotchas.  But a dict is 
legal in all of them.


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


Re: [Tutor] making a random list, then naming it

2013-05-24 Thread Jim Mooney
On 24 May 2013 18:10, Dave Angel  wrote:

> Is lists[(3,8)]  really so much harder to type than
> list_3_8  ?
>

You have a point. I hate underlines - my finger always misses them.
Keyboards were not designed for programming ;')

Anyway, I just thought I'd try exec, but it's giving me fits putting it in
a function so I can do multiple lists. A dictionary looks more manageable.

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


Re: [Tutor] making a random list, then naming it

2013-05-24 Thread Dave Angel

On 05/24/2013 08:04 PM, Jim Mooney wrote:

You forgot to give the author attribution on the following paragraph.  I 
happen to recognize my own text, but that's not a nice thing to do. 
Notice above where it says  "Jim Mooney wrote" ?



The short answer is that Python is not designed to be able to do such a
thing.  You're advised instead to make a dictionary, where the key is the
name you generate



I was probably unclear what I wanted to do. Basically, enter a string of
number pairs of lengths and maxvals to create and print multiple lists, and
name them, so I could fool around with them and not have to remember each
one. I noodled around google and found something to do that.


exec and eval can do all sorts of magic.  When there's a different 
answer, that other answer is nearly always preferable.  The problem is 
that once you play this trick to save yourself some keystrokes while 
debugging, you may think you understand the functionality and the risks 
it involves, and use it on code that matters.


As I said, you should make a dictionary.  You can then give names to 
each item in the dictionary, and those names may or may not actually be 
valid identifiers.


Is lists[(3,8)]  really so much harder to type than
list_3_8  ?

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


Re: [Tutor] making a random list, then naming it

2013-05-24 Thread Jim Mooney
> The short answer is that Python is not designed to be able to do such a
> thing.  You're advised instead to make a dictionary, where the key is the
> name you generate


I was probably unclear what I wanted to do. Basically, enter a string of
number pairs of lengths and maxvals to create and print multiple lists, and
name them, so I could fool around with them and not have to remember each
one. I noodled around google and found something to do that.

I haven't done the multiple lists or listing those lists, or input
filtering yet, but I named one list, tested it as a real int list, and it
seems to work. Unless I'm confused ;')

import random
random.seed

listparameters = raw_input('\nEnter two numbers, space separated, for the
length and largest value of a zero-starting random list, which can be used
as variable name: randlist.list_len_max , where len is the list length you
entered, and max is the largest value\n')

listargs = listparameters.split()
rlist = []
length = int(listargs[0])
maxval = int(listargs[1])
for r in range(0,length):
rlist.append(random.randint(0,maxval))

listlenmax = 'list' + '_' + str(length) + '_' + str(maxval) + ' = rlist'

exec listlenmax

#I entered 20 and 120 just as a test, but any ints will work. The program
will be   changed to list the data names and lists created, accept more
than one number pair so I have multiple lists, and I'll add some input
filters, then put it in jimports

list_20_120[0] += 10042
# test to see if it's a real int list by adding a large number to element
zero

print list_20_120
#this is hard coded but I'll make a list of names taken from input, that I
can use

#result from one run was:
[10095, 98, 110, 89, 86, 2, 51, 88, 36, 20, 85, 84, 98, 20, 11, 64, 17,
111, 22, 5]

#The first number is bigger than the 120 max so it must work.

#the docs on exec were kind of inscrutable. I think some of the docs expect
you to know what you're doing before you read them ;')  But I found some
examples and ran a bunch of monkey-see, monkey-do progs. I haven't really
gotten to dictionaries yet, but this seems to work.
___
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] Fwd: Difference between types

2013-05-24 Thread Dave Angel

On 05/24/2013 02:53 PM, Albert-Jan Roskam wrote:




A tuple is defined by commas, depending on context. However,
parentheses are typically required because commas have low precedence.

 >>> 1, 2 + 3, 4
 (1, 5, 4)

 >>> (1, 2) + (3, 4)
 (1, 2, 3, 4)

An empty tuple is a special case:

 >>> x = ()
 >>> type(x)
 


Why do I need to use a trailing comma to create a singleton tuple? Without a comma it 
seems to mean "parenthesized single object", ie the parentheses are basically 
not there.

type((0,))



type((0))



(0)

0

x = (,)

SyntaxError: invalid syntax


(0,0)

(0, 0)



Your answer is right above your question, in the part you quoted 
(without attribution) from eryksun.


The empty tuple is specified with ().  But for any tuple with one or 
more members, it's the commas that turn it into a tuple.  The parens are 
not necessarily needed unless the statement is complex enough that we 
need them for precedence.


So   x = 3,4

makes a one-tuple out of 3 and 4.  If you want a one-tuple (which is NOT 
a singleton), you need a silly-looking comma to specify it:

 x = 5,

In other words, comma is the operator, not parentheses.  Parentheses are 
used to change precedence (as well as for function parameters and 
arguments.)


Note that one thing that confuses newcomers is the dual use of commas 
and parens for functions.  If you need a literal tuple as a function 
argument, you will need extra parens so the comma aimed at the tuple 
doesn't get confused with the comma used to separate arguments.


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


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread Albert-Jan Roskam


> A tuple is defined by commas, depending on context. However,
> parentheses are typically required because commas have low precedence.
> 
>     >>> 1, 2 + 3, 4
>     (1, 5, 4)
> 
>     >>> (1, 2) + (3, 4)
>     (1, 2, 3, 4)
> 
> An empty tuple is a special case:
> 
>     >>> x = ()
>     >>> type(x)
>     

Why do I need to use a trailing comma to create a singleton tuple? Without a 
comma it seems to mean "parenthesized single object", ie the parentheses are 
basically not there.
>>> type((0,))

>>> type((0))

>>> (0)
0
>>> x = (,)
SyntaxError: invalid syntax

>>> (0,0)
(0, 0)

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


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread Citizen Kant
It's perfect, even if I'm not able to understand everything that's
stated there. Then 2.5 is Operators, and 2.6 is Delimiters,
that also goes in the line of what I'm thinking about.

Thanks for the "you seem to be talking about", coz
I'm learning not by memory but trying to understand,
and sometimes I have the idea but don't have the knowledge
to communicate the doubt properly.

Thanks again.



2013/5/24 eryksun 

> On Fri, May 24, 2013 at 12:52 PM, Citizen Kant 
> wrote:
> > They are values since they cannot be reduced by rewriting any further.
>
> You seem to be talking about the "atoms" of the language: identifiers,
> literals, parenthesized forms, displays, and so on. Please read
> sections 2.3 (identifiers), 2.4 (literals), and 6.2 (atoms) in the
> language reference:
>
> http://docs.python.org/3/reference
>
> It may not answer all of your questions, but it's at least a common
> reference for discussion.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread eryksun
On Fri, May 24, 2013 at 12:52 PM, Citizen Kant  wrote:
> They are values since they cannot be reduced by rewriting any further.

You seem to be talking about the "atoms" of the language: identifiers,
literals, parenthesized forms, displays, and so on. Please read
sections 2.3 (identifiers), 2.4 (literals), and 6.2 (atoms) in the
language reference:

http://docs.python.org/3/reference

It may not answer all of your questions, but it's at least a common
reference for discussion.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread eryksun
On Fri, May 24, 2013 at 7:04 AM, Citizen Kant  wrote:
> Same happens with the tuple (100, 'value', 2);  where parenthesis and semi
> colon work as a rule, setting the shape of a value named tuple that's
> different to the shape of a value named list. At the same time both shapes
> are equal (since both are value).

A semicolon is an optional way to delimit statements in Python. It's
rarely used since stacking multiple statements on a single line gets
ugly fast.

A tuple is defined by commas, depending on context. However,
parentheses are typically required because commas have low precedence.

>>> 1, 2 + 3, 4
(1, 5, 4)

>>> (1, 2) + (3, 4)
(1, 2, 3, 4)

An empty tuple is a special case:

>>> x = ()
>>> type(x)

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


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread Citizen Kant
When I say "coding", anyone can think about what coding is
in his own daily work, but that's not my way.
I'll try to refine the concept: right now I'm learning,
if I say "coding" I refer to what I type inside
my file named learningpythoncode.py that,
believe it or not, starts with:

# """After the hash can go my comment.
That's the first thing I've learned, and it's useful since
this way I don't feel like as don't knowing any language
at all. This is part of the code that Python doesn't
compute, but this isn't less code.

Since I am using the triple quotation, I can continue:
On the left side of the hash will go some code, not like
this one, but one that Python can in fact compute.
It seems useful to know first what am I trying to accomplish,
so first I must find out what does Python is expecting from me.
I understand that Python works with values,
so on the left side of the hash, whatever one codes, must be VALUE.

Writing code that Python can compute depends entire on:
VALUE having a somehow useful definition.
This definition will help me to look at my own code, recognize
the value in it (correctness), and let me know that I'm doing well.
I can always rely on Python spiting an error message but I
prefer the understanding way.

I think I've found a definition for value and it seems to say
that is a *normal form* or element of the system which cannot be
reduced by rewriting any further."""

9 # """ Is my first attempt on the left side of the hash. 9 is a value
since it cannot be reduced by rewriting any further.
Same goes for the other integers 0 1 2 3 4 5 6 7 8.
They are values since they cannot be reduced by rewriting any further.
Then I consider to code another value, like A, that looks like if
cannot be reduced by rewriting any further but I arrived
to the fact that Python doesn't consider those characters like A
as able to take part in its computations until I put them between
apostrophes or quotation marks."""

'A' # """ I put A between apostrophes and it suddenly turned to something
that cannot be reduced by rewriting any further,
or unless that seems to me.
I thought: if one can turn to value anything by putting it between
apostrophes or quotation marks, then the trick must be in the
pair of apostrophes or quotation marks.

That's how I came to the conclusion that the pair of apostrophes
are, in fact, the value, and that Python treats that kind of delimiter
"" as a value, no matter what one puts inside it.

Seems like if 0 1 2 3 4 5 6 7 8 9 were values which cannot be
reduced by rewriting any further.

And that "" was another type of value since cannot be
reduced by rewriting any further

This [] is value since cannot be reduced by rewriting any further.

This {} is value since cannot be reduced by rewriting any further.

This ""  is another value is value since cannot be reduced
by rewriting any further.

Then seem that those customized and customizable
delimited values were like a bunch of new numbers with
a void that one can fill if necessary.

Then seems that there are some other cases of value
that doesn't match with those above.

Cases like my_variable (not int, nor str) maybe values
only if they are assigned to one of the above values,
or assigned to a name that was previously assigned
to one of the above values.

Then True and False as bool, are somehow names that are
assigned to a value like the ones above.

Then any other Python keyword, (def for example) comes to be a
built-in value since it's (so to speak) built-in
assigned to one of the above values, or assigned to a name
that was previously assigned to one of the above values.

This way, everything one can code in Python remains
value and Python doesn't spit its error messages.

Then remains the fact that I have + - * / and other values that "act" as
operators.
According to Python they don't have a defined type, since if I type

type(+)

leads to an error."""

Is it possible to draw a line like this (that goes all along Python)
and grasp at least "one complete aspect" of the language?



2013/5/24 Steven D'Aprano 

> Citizen Kant,
>
> will you please fix your email quoting? As it is, you are plagiarizing me,
> by quoting me word for word without attribution or any hint that you are
> quoting me.
>
> Do you notice that everyone else quotes people by name, and prefixes their
> words with > quote marks? This is the normal standard on email. If you are
> using something that breaks that standard (possibly Gmail?) and cannot set
> it to follow the normal rules for quoting, then you are going to frustrate
> and annoy people, possibly to the point that they banish your emails to the
> "kill-file" and stop answering your questions. Harsh, but a fact of life.
>
> If you ask, I'm sure people who know more about Gmail will help you fix
> your settings.
>
> Thanks,
>
>
>
>
> --
> Steven
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.pyt

Re: [Tutor] keyboard interrupt

2013-05-24 Thread Marc Tompkins
On Thu, May 23, 2013 at 3:52 PM, Steven D'Aprano wrote:

> On 24/05/13 06:37, Jim Mooney wrote:
>
>> Apparently Wing isn't as savvy as IDLE when it comes to communicating
>>> with the subprocess. I've only searched for about a minute, but
>>> apparently the way this works in Wing is to "Restart Shell":
>>>
>>> http://stackoverflow.com/a/**10360503/205580
>>> http://www.wingware.com/doc/**debug/interactive-python-shell
>>>
>>> This kills the suprocess and starts a new interpreter. Crude, but it
>>> should get the job done.
>>>
>>
>> Thanks. I'll put stackoverflow on my bookmarks.
>>
>
> Beware though, while there are often some very good answers on
> Stackoverflow, there are also very many people who are nowhere near as
> knowledgeable as they think, giving terrible answers, and still having
> large scores. (One particular person comes to mind, I forget his name but
> he has a *very* high score which means lots of people are voting for his
> answers, and yet every time without exception I've seen him reply to
> someone he has been rude, missed the entire point of their question, or
> given them bad advice. Or all three at once.)
>

I love, love, love StackOverflow (and the whole StackExchange ecosystem),
but it's unfortunately susceptible to being gamed.  Anyone can edit a
question (or an answer), and if the edit is allowed to stand the editor
gets 2 points.  There are millions of questions, so this process can be
repeated ad nauseam.  I used to spend a lot of time on
english.stackexchange.com, and one of the reasons I got fed up with it is
exactly that: unhelpful, opinionated users whose scores were inflated to
make them seem authoritative.  One of them edited several of my answers,
making no change except to turn dashes into Unicode em dashes - and his
score was four times higher than mine, despite hardly having any answers
accepted (due to being a rude, ignorant loudmouth).  I have no problem at
all with true experts having higher scores than mine (especially if they
answer more questions than I, and do it beautifully) but I came to resent
being ranked behind jerks.

The system still _mostly_ works, though, and it sure beats the hell out of
ExpertSexChange or whatever they're calling it these days...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread eryksun
On Fri, May 24, 2013 at 9:31 AM, Citizen Kant  wrote:
> Sorry. I'm not doing this on purpose, but I'm doing it anyway, so I'll check
> how to fix it.

You're replying with rich text, for which Gmail has a lot of its own
custom CSS (e.g. the gmail_quote class). In Gmail I see the quoted
text as a purplish color, but it looks like you're editing out the
block quotes on parts. This prevents the normal '>' quote indicator
from being inserted in the auto-generated plain text.

Just reply-all in plain text mode and follow the conventions you see
in other people's replies.

Personally, reading and editing plain text with a proportional font
annoys me -- a lot. Here's a Greasemonkey script to use a monospace
font for plain text in Gmail:

http://userscripts.org/scripts/show/17869

Also, when you post code remember to use less than 70 characters per
line. Gmail has a 'feature' to automatically hard wrap plain-text
messages at about 70 characters, which it applies *after* you send
(i.e. there's no indicator in the composer... brilliant).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread Citizen Kant
Sorry. I'm not doing this on purpose, but I'm doing it anyway, so I'll
check how to fix it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread Steven D'Aprano

Citizen Kant,

will you please fix your email quoting? As it is, you are plagiarizing me, by 
quoting me word for word without attribution or any hint that you are quoting 
me.

Do you notice that everyone else quotes people by name, and prefixes their words with > 
quote marks? This is the normal standard on email. If you are using something that breaks 
that standard (possibly Gmail?) and cannot set it to follow the normal rules for quoting, 
then you are going to frustrate and annoy people, possibly to the point that they banish 
your emails to the "kill-file" and stop answering your questions. Harsh, but a 
fact of life.

If you ask, I'm sure people who know more about Gmail will help you fix your 
settings.

Thanks,



--
Steven

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


Re: [Tutor] Issue w/ program: Flip a coin and count heads and tails

2013-05-24 Thread Asokan Pichai
On Fri, May 24, 2013 at 4:54 PM, Rafael Knuth wrote:

>  I am writing a program in Python 3.3.0 which flips a coin 10 x times and
>> then counts the number of heads and tails. It obviously does something else
>> than I intended, and I am wondering what I did wrong:
>>
>
> What is that you intended?
> Please explain that.
>
> I want that program to flip a coin 10 x times and then count the number of
> heads and tails.
> That's very much it.
>

Then you have set up the while loop right. It loops 10 times.
But if it is a head you are counting heads. Now if it is a tail
you are discarding and tossing again!

That is the effect of
while flips < 10:
flips = flips + 1
if random.randint(1,2) == 1:
 - if it is not head?
heads = heads + 1
print("We've got " + str(heads) + " heads here."
if random.randint(1,2) == 2:
 - this is the second toss I am talking about
tails = tails + 1

Now if you replace the second toss by an "else" and count it as a tail
you should go towards the code you are looking for. Try it and tell us
how it goes. All the best

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


Re: [Tutor] Fwd: Difference between types

2013-05-24 Thread Dave Angel

On 05/24/2013 07:04 AM, Citizen Kant wrote:

Are you referring to this definition?

http://en.wikipedia.org/wiki/**Value_%28computer_science%29



Any chance you can fix your use of gmail to conform to the usual 
standards?  It does it right by default.  We have lots of gmail users on 
here, but you're almost the only one who doesn't have the quote marks on 
the stuff you're quoting from earlier messages, nor the attribution.  So 
by breaking those conventions, you imply that you wrote the above text, 
when really you're
quoting Steven anonymoously.  Worse, then when you start your own text, 
there's no distinguishing them, unless a reader happens to have read the 
other message recently enough to remember.


 



I'm referring to that definition. I've found out that, unless for me, it's
useful to think Python in this line.


But that page is mostly wrong or misleading for Python.  And it assumes 
you already know what an expression is, so it's the wrong definition for 
you as well.


That page refers to another page:
   http://en.wikipedia.org/wiki/Expression_(computer_science)

to try to define expression.  But since that one says that an expression 
is a combination of many things, including value, it still doesn't help 
you much, because it's circular.


You concluded for example that A is a value, which of course it's not, 
in source code.  It might be a variable (or the Python approximation to 
variable), but only if it's a token within the source code.


Tell me, when you learned to drive, did you start by defining what a 
thread was?  After all, an engine would fall apart without threaded 
bolts, and without an engine there's no point in driving.



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


Re: [Tutor] Issue w/ program: Flip a coin and count heads and tails

2013-05-24 Thread Wolfgang Maier
On 24 May 2013 12:01, Rafael Knuth  gmail.com> wrote:
> Hello,
>
> I am writing a program in Python 3.3.0 which flips a coin 10 x times and
> then counts the number of heads and tails. It obviously does something else
> than I intended, and I am wondering what I did wrong:
>
> import random
>
> print ("""
>
> This program flips a coin 10 times.
>
> It then counts the number of heads and tails.
>
> """)
>
> flips = 0
>
> heads = 0
>
> tails = 0
>
> while flips < 10:
>
> flips = flips + 1
>
> if random.randint(1,2) == 1:
>
> heads = heads + 1
>
> print("We've got " + str(heads) + " heads here."
>
> if random.randint(1,2) == 2:
>
> tails = tails + 1
>
> print("We've got " + str(tails) + " tails here.")
>
> This is what I get as output:
>
> This program flips a coin 10 times.
>
> It then counts the number of heads and tails.
>
> We've got 1 tails here.
>
> We've got 1 heads here.
>
> We've got 2 tails here.
>
> We've got 2 heads here.
>
> We've got 3 tails here.
>
> We've got 3 heads here.
>
> We've got 4 tails here.
>
> We've got 5 tails here.
>
> We've got 4 heads here.
>
> We've got 6 tails here.
>
> We've got 7 tails here.
>
> We've got 5 heads here.
>

You're printing from within your while loop, so *everytime* through it, your
program prints either the heads or the tails message.
In addition, your throwing the coin twice during each run of the loop:
if random.randint(1,2) == 1   # that's one
if random.randint(1,2) == 2   # that's another one

flip the coin once instead and store the outcome in a variable, like:
result = random.randint(1,2)

if result == 1:
   # do head stuff here
else:
   # do tail stuff here

That should fix the unexpected behavior. However, if all you want to do is,
as you say, count the total numbers of head and tail results, this is an
incredibly complicated way to do it.
This short form suffices:

import random

flips = 10
s = sum(random.randint(0,1) for flip in range(flips))

print ("We've got " + str(flips-s) + " heads and " + str(s) + " tails here.")

Read about range, comprehensions and generator expressions if you have
trouble understanding the third line.
Best,
Wolfgang



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


Re: [Tutor] Issue w/ program: Flip a coin and count heads and tails

2013-05-24 Thread Omar Abou Mrad
On Fri, May 24, 2013 at 2:08 PM, Asokan Pichai wrote:

>
> 
> Is this an actual output??? Did the program stop here at 5 heads and 7
> tails?
> 
> Asokan Pichai
>
>
Adding fuel to fire.

He actually got 12 Tails and 8 Heads!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue w/ program: Flip a coin and count heads and tails

2013-05-24 Thread Rafael Knuth
>
> I am writing a program in Python 3.3.0 which flips a coin 10 x times and
> then counts the number of heads and tails. It obviously does something else
> than I intended, and I am wondering what I did wrong:
>

What is that you intended?
Please explain that.

I want that program to flip a coin 10 x times and then count the number of
heads and tails.
That's very much it.


On Fri, May 24, 2013 at 1:08 PM, Asokan Pichai wrote:

>
>
> On Fri, May 24, 2013 at 4:31 PM, Rafael Knuth wrote:
>
>> Hello,
>>
>> I am writing a program in Python 3.3.0 which flips a coin 10 x times and
>> then counts the number of heads and tails. It obviously does something else
>> than I intended, and I am wondering what I did wrong:
>>
>
> What is that you intended?
> Please explain that.
>
>>
>> import random
>>
>> print ("""
>>
>> This program flips a coin 10 times.
>>
> Actually this is wrong. The program does something else.
>
>
>>
>> It then counts the number of heads and tails.
>>
>> """)
>>
>> flips = 0
>>
>> heads = 0
>>
>> tails = 0
>>
>> while flips < 10:
>>
>> flips = flips + 1
>>
>> if random.randint(1,2) == 1:
>>
>> heads = heads + 1
>>
>> print("We've got " + str(heads) + " heads here."
>>
>> if random.randint(1,2) == 2:
>>
>> tails = tails + 1
>>
>> print("We've got " + str(tails) + " tails here.")
>>
>
>> This is what I get as output:
>>
>> This program flips a coin 10 times.
>>
>> It then counts the number of heads and tails.
>>
>> We've got 1 tails here.
>>
>> We've got 1 heads here.
>>
>> We've got 2 tails here.
>>
>> We've got 2 heads here.
>>
>> We've got 3 tails here.
>>
>> We've got 3 heads here.
>>
>> We've got 4 tails here.
>>
>> We've got 5 tails here.
>>
>> We've got 4 heads here.
>>
>> We've got 6 tails here.
>>
>> We've got 7 tails here.
>>
>> We've got 5 heads here.
>>
> Is this an actual output??? Did the program stop here at 5 heads and 7
> tails?
>
>
>>
>> Can anyone help?
>>
>> Thank you so much!
>>
>> All the best,
>>
>> Rafael
>>
>
> Asokan Pichai
>
> "Expecting the world to treat you fairly because you are a good person is
> a little like expecting the bull to not attack you because you are a
> vegetarian"
>
> ___
> 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] Issue w/ program: Flip a coin and count heads and tails

2013-05-24 Thread Asokan Pichai
On Fri, May 24, 2013 at 4:31 PM, Rafael Knuth wrote:

> Hello,
>
> I am writing a program in Python 3.3.0 which flips a coin 10 x times and
> then counts the number of heads and tails. It obviously does something else
> than I intended, and I am wondering what I did wrong:
>

What is that you intended?
Please explain that.

>
> import random
>
> print ("""
>
> This program flips a coin 10 times.
>
Actually this is wrong. The program does something else.


>
> It then counts the number of heads and tails.
>
> """)
>
> flips = 0
>
> heads = 0
>
> tails = 0
>
> while flips < 10:
>
> flips = flips + 1
>
> if random.randint(1,2) == 1:
>
> heads = heads + 1
>
> print("We've got " + str(heads) + " heads here."
>
> if random.randint(1,2) == 2:
>
> tails = tails + 1
>
> print("We've got " + str(tails) + " tails here.")
>

> This is what I get as output:
>
> This program flips a coin 10 times.
>
> It then counts the number of heads and tails.
>
> We've got 1 tails here.
>
> We've got 1 heads here.
>
> We've got 2 tails here.
>
> We've got 2 heads here.
>
> We've got 3 tails here.
>
> We've got 3 heads here.
>
> We've got 4 tails here.
>
> We've got 5 tails here.
>
> We've got 4 heads here.
>
> We've got 6 tails here.
>
> We've got 7 tails here.
>
> We've got 5 heads here.
>
Is this an actual output??? Did the program stop here at 5 heads and 7
tails?


>
> Can anyone help?
>
> Thank you so much!
>
> All the best,
>
> Rafael
>

Asokan Pichai

"Expecting the world to treat you fairly because you are a good person is a
little like expecting the bull to not attack you because you are a
vegetarian"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue w/ program: Flip a coin and count heads and tails

2013-05-24 Thread Bod Soutar
On 24 May 2013 12:01, Rafael Knuth  wrote:
> Hello,
>
> I am writing a program in Python 3.3.0 which flips a coin 10 x times and
> then counts the number of heads and tails. It obviously does something else
> than I intended, and I am wondering what I did wrong:
>
> import random
>
> print ("""
>
> This program flips a coin 10 times.
>
> It then counts the number of heads and tails.
>
> """)
>
> flips = 0
>
> heads = 0
>
> tails = 0
>
> while flips < 10:
>
> flips = flips + 1
>
> if random.randint(1,2) == 1:
>
> heads = heads + 1
>
> print("We've got " + str(heads) + " heads here."
>
> if random.randint(1,2) == 2:
>
> tails = tails + 1
>
> print("We've got " + str(tails) + " tails here.")
>
> This is what I get as output:
>
> This program flips a coin 10 times.
>
> It then counts the number of heads and tails.
>
> We've got 1 tails here.
>
> We've got 1 heads here.
>
> We've got 2 tails here.
>
> We've got 2 heads here.
>
> We've got 3 tails here.
>
> We've got 3 heads here.
>
> We've got 4 tails here.
>
> We've got 5 tails here.
>
> We've got 4 heads here.
>
> We've got 6 tails here.
>
> We've got 7 tails here.
>
> We've got 5 heads here.
>
> Can anyone help?
>
> Thank you so much!
>
> All the best,
>
>
>
> Rafael
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Hint: Look at your second if statement

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


[Tutor] Fwd: Difference between types

2013-05-24 Thread Citizen Kant
Are you referring to this definition?

http://en.wikipedia.org/wiki/**Value_%28computer_science%29

As far as it goes, that's not an unreasonable rule of thumb, but it isn't
bullet-proof. What, for example, do you make of this:

0x09

Is that a value? I say yes, because that is a literal expression for the
natural number 9. It merely happens to use hexadecimal notation instead of
decimal notation. Another language might define keywords one, two, three
... nine, ten which are also literal expressions for the same natural
number, only using English words instead of numerals.

But let's not worry about hypothetical languages with such keywords. Even
in Python, each of these represent the exact same value:

9 0x09 0o10 0b1001

They are the same value, using different notation.

I'm referring to that definition. I've found out that, unless for me, it's
useful to think Python in this line. That leads me to think, first, that
every single character is in itself a value, any single thing that one can
find inside a Python script is somehow value, all are characters. So, since
Python only (is this correct?) works with values, then came the question
about how to create different kinds of value, so to speak more complex,
that respond to value's definition. The answer I've managed to give to
myself is that this could be accomplished by: setting a rule that makes
whatever to "have the shape" of a value. That's to say, for example:
'apostrophes' act as the shape of a value named string, no matter what one
puts inside it. So 'apostrophes' are just a label that Python considers the
shape of a value. Same happens with the tuple (100, 'value', 2);  where
parenthesis and semi colon work as a rule, setting the shape of a value
named tuple that's different to the shape of a value named list. At the
same time both shapes are equal (since both are value).

As far as I can think, the same must happen with all the other types of
value in Python.

Then, something like my_variable doesn't respond to value's definition
(even if no one can say that doesn't "look like" a normal form) until a
value it's assigned to it. Then
if my_variable = 9

if my_variable = 'A'
the 

I'm not very strong in maths, so I can't tell what's going on with 0x09.
Could it be that simple as that anything between integers is int, and
that's why one cannot start a variable name with a number since a
variable's name starting with a number could be perfectly confused with
some integer?

The point is, given this Python environment, would it be correct to look
for some truth, asking to myself "in which way every single thing in Python
comes to be a value (following value's wikipedia definition)?

Anyway, this line of thinking doesn't lead me to understand where's the
label for a value (acting as operator) like + or - or * for example. I
simply tend to think that maybe the difference is so to speak built-in in
Python.


Likewise for every object. Compound objects are also values:

iter([12, 3, None, "hello world!", 4.5, ('a', 'b', 3), {}])

It looks that your example match with the idea I've presented above. Am I
right? The fact that you wrote {} , looks like the pair of { } itself is
the value that one can always fill with some other proper value if it's
necessary.

 type('A')
> 
>
> The question is, in order to understand: does this apostrophes thing has a
> more profound reason to be attached to the letters or it's just a
> conventional way to set a difference between letters and numbers?
>

The later. It is a long standing tradition in computer programming that
so-called "strings" (ordered sequences of letters, digits and other
characters) are defined using a notation that includes quotation marks as
delimiters. In contrast, numbers are written in straight numeric form,
usually in base-10 but sometimes in other bases.

I guess that "delimiter" sound perfect to name what I use to see as the
shape or skin of values: 'delimiters' [delimiters] {delimiters}
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Issue w/ program: Flip a coin and count heads and tails

2013-05-24 Thread Rafael Knuth
Hello,

I am writing a program in Python 3.3.0 which flips a coin 10 x times and
then counts the number of heads and tails. It obviously does something else
than I intended, and I am wondering what I did wrong:

import random

print ("""

This program flips a coin 10 times.

It then counts the number of heads and tails.

""")

flips = 0

heads = 0

tails = 0

while flips < 10:

flips = flips + 1

if random.randint(1,2) == 1:

heads = heads + 1

print("We've got " + str(heads) + " heads here."

if random.randint(1,2) == 2:

tails = tails + 1

print("We've got " + str(tails) + " tails here.")

This is what I get as output:

This program flips a coin 10 times.

It then counts the number of heads and tails.

We've got 1 tails here.

We've got 1 heads here.

We've got 2 tails here.

We've got 2 heads here.

We've got 3 tails here.

We've got 3 heads here.

We've got 4 tails here.

We've got 5 tails here.

We've got 4 heads here.

We've got 6 tails here.

We've got 7 tails here.

We've got 5 heads here.

Can anyone help?

Thank you so much!

All the best,



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