Re: [Tutor] (no subject)

2008-10-01 Thread Pierre Dagenais

Timothy Grant wrote:

On Tue, Sep 30, 2008 at 10:20 PM, Pierre Dagenais
<[EMAIL PROTECTED]> wrote:
  

kayla bishop wrote:


I can't figure out how to write a program where you flip a coin 100 times
and it keeps track of how many heads and tails you flipped but it has to be
random. Can you please help
_
Get more out of the Web. Learn 10 hidden secrets of Windows Live.

http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
 

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


No virus found in this incoming message.
Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database:
270.7.5/1698 - Release Date: 29/09/2008 7:25 PM


  

Here is how one newbie would do it:


import random

# Initialize variables
head = 0
tail = 0

# Flip the coin a hundred times
for x in range(100):
  choice = random.randint(1,2)
 # Is it 'head'?
  if choice == 1 :
  head = head + 1
 # If not 'head' then it must be tail
  else :
  tail = tail + 1
 print "head = ",head
print "tail = ",tail


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




Please let us know if Pierre gets an an "A" on that assignment or not Kayla.

  
If that's what it is, and I thought it might be, he won't learn how to 
program but on exam day he'll realize that cheating is very expensive. A 
great lesson to learn early in life if possible. On the other hand if 
Kayla is just new to programming and learning on his own, then some 
silly mistake can take weeks to figure out and is a huge waste of time, 
as I experienced when learning basic on my beloved ZX81. Besides any 
teacher worth it's wiff should scan this list for cheaters, right?

Have a nice day, both of you.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python: can't open file 'test.py' : [Errno 2] No such file or directory

2008-10-01 Thread Pierre Dagenais

Timothy Grant wrote:

On Tue, Sep 30, 2008 at 9:01 PM, Pierre Dagenais <[EMAIL PROTECTED]> wrote:
  

Timothy Grant wrote:


On Tue, Sep 30, 2008 at 12:58 PM, Pierre Dagenais
<[EMAIL PROTECTED]> wrote:

  

The file test.py is in I:\Python25\MyCode,
if I enter:

 C:\>Python25\MyCode\python25 test.py at the DOS prompt, everything works
as
I would expect.

However when I enter the same command from any other directory I get this
error:

 C:\>python test.py
 python: can't open file 'test.py' : [Errno 2] No such file or directory

I've set the environment variable pythonpath as
 C:\>set pythonpath = C:\\Python25\\MyCode
what am I doing wrong,
Thank u for your help,
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




You need to give the full path to your test.py file.

PYTHONPATH sets the python library search path.


 Thank you Tim,
Definitively C:\python \python25\mycode\test.py does work. If you're right
about having to give the full path, and I suspect you are, Then this means
that python knows to search the currennt working directory for  the file to
execute, but nowhere else. It seems a strange behavior. Maybe this is on Mr.
Guido van Rossum todo list.

  


Why is that strange? Would you expect any other program not on the
path to execute without a fully qualified path? Make your python code
executable, and put it somewhere on the path and I'm quite sure it
would run as expected (though it has been over 10 years since I last
had to work on a Windows box so I'm not quite sure how to do that).

  


Yes Tim, but both PATH and PYTHONPATH are set to \python25 and 
\python25\MyCode, so I don't understand why python searches the CWD but neither 
the path nor pythonpath directories.


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


Re: [Tutor] python: can't open file 'test.py' : [Errno 2] No such file or directory

2008-10-01 Thread Alan Gauld


"Pierre Dagenais" <[EMAIL PROTECTED]> wrote



The file test.py is in I:\Python25\MyCode,


There is an inconsistency here.
You say at this point that the drive is I


I've set the environment variable pythonpath as
 C:\>set pythonpath = C:\\Python25\\MyCode


But here you add a folder in the C drive?


Definitively C:\python \python25\mycode\test.py does work.
If you're right about having to give the full path, and I suspect 
you are, Then this means that python knows to search the currennt 
working directory for  the file to execute, but nowhere else.


Correct, just like every other program.
If you run notepad foo.txt notepad will open a new foo.txt
in the current folder it will not search your drive to find some
other foo.txt that you created prevbiously.
Why would python be any different?

The trick to do what you want is not to execute python but
to execute the script and allow the OS to associate Python
with it.

So either just type the script name into the prompt (assuming
it is on the PATH) or double click in explorer and Windows will
find Python itself.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


[Tutor] Idle and windows XP firewall

2008-10-01 Thread David Holland
At work I have windows XP service pack 3 and although I have sys admin I can 
not use idle.
I have googled but no success - any ideas?


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


Re: [Tutor] python: can't open file 'test.py' : [Errno 2] No such file or directory

2008-10-01 Thread Alan Gauld
"Pierre Dagenais" <[EMAIL PROTECTED]> wrote 

Yes Tim, but both PATH and PYTHONPATH are set 
to \python25 and \python25\MyCode, so I don't understand 
why python searches the CWD but neither the path nor 
pythonpath directories.


Because that's how Windows works, its how Bill Gates 
decided it should be... Its what Windows calls the 
Working Folder and by default for the command prompt 
its the one you are in.


It  can be argued that it is "A Good Thing" since it allows you 
to have several python scripts of the same name and not 
have the wrong script accidentally being started.


HTH,

Alan G.

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


[Tutor] Heads & Tails was Re: (no subject)

2008-10-01 Thread Alan Gauld
"kayla bishop" <[EMAIL PROTECTED]> wrote 


Please use a sensible subject line

I can't figure out how to write a program where you flip a 
coin 100 times and it keeps track of how many heads 
and tails you flipped but it has to be random. 


This sounds like homework so we cannot give you a solution.

But here are some questions that may help you find a solution:

1) could you write a program to ask the user for a head or 
a tail and store the answer?


2) could you make that program repeat 10 times and store 
the count of heads only?


3) could you store the total for heads and tails into two 
separate totals?


4) could you replace the user input with a random number?

5) could you make the random number result be one of two 
values - say head and tail?


6) could you increase the repetitions to 100?

Done all that? Then you've solved your problem.
If you didn't where did you get stuck?
Show us your code and any errors.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] (no subject)

2008-10-01 Thread Kent Johnson
On Wed, Oct 1, 2008 at 3:55 AM, Pierre Dagenais <[EMAIL PROTECTED]> wrote:
> Timothy Grant wrote:

> If that's what it is, and I thought it might be, he won't learn how to
> program but on exam day he'll realize that cheating is very expensive. A
> great lesson to learn early in life if possible. On the other hand if Kayla
> is just new to programming and learning on his own, then some silly mistake
> can take weeks to figure out and is a huge waste of time, as I experienced
> when learning basic on my beloved ZX81. Besides any teacher worth it's wiff
> should scan this list for cheaters, right?

Regardless of how you feel about cheating, or whether the teacher is
reading the list, the policy on this list is not to knowingly supply
explicit answers to homework questions. We give hints and help
learners when they are stuck. You didn't even give Kayla a chance to
get stuck.

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


Re: [Tutor] (no subject)

2008-10-01 Thread bhaaluu
Since an answer has already been given (by Pierre Dagenais),
let's see if we can help you "figure it out".

The first step is to read the program specification, or, in your
case, read the homework problem very carefully. Since most
computer programs have INPUT, PROCESS, and OUTPUT, let's
try to look at the problem from that viewpoint, shall we?

On Tue, Sep 30, 2008 at 10:47 PM, kayla bishop
<[EMAIL PROTECTED]> wrote:
> I can't figure out how to write a program where you flip a coin 100 times
> and it keeps track of how many heads and tails you flipped but it has to be
> random. Can you please help

Well, since you said the magic word, I'll try.

First of all, a hash mark designates a comment.
A comment isn't read by the computer. Everything
after a hash mark isn't read by the computer, BUT
you can read it, and that's why it is always a good
idea to use comments in your program.

We can break down the problem into INPUT, PROCESS
and OUTPUT as follows:

> I can't figure out how to [INPUT, PROCESS, OUTPUT]
> write a program
> where you flip a "coin" [INPUT]
> 100 times [PROCESS]
> and it keeps track of how many heads and tails you flipped [OUTPUT]
> but it has to be random. [PROCESS]

You have a coin which has two sides "heads" and "tails",
so that is the INPUT.
You flip the coin 100 times, and each time you flip it, the result is random.
That is the PROCESS.
You keep track of how many times it comes up heads and tails.
That is the OUTPUT.
That wasn't too difficult, was it?

Python has a lot of modules that are already written
for you. That's way cool because you don't have to
figure that part out! Doing random things is one of
those things you don't have to figure out, because
there is a module called random. You can use the
stuff in random by importing it into your program.
Find out more about random in the Python documentation.
This is usually done at the top of the program.

#!/usr/bin/python
# flipCoin.py
# 2008-10-01
# b h a a l u u at g m a i l dot c o m

import random

#Next you need some INPUT. I think we decided that the
#coin would be INPUT, right? And the coin has 'heads' and 'tails'?
#Let's make a "list" for the coin:

coin = ['heads', 'tails']

#Lists are surrounded by square brackets.
#But the program needs to choose those randomly, right?

flip = random.choice(coin)

#Now, let's count how many times you flip the coin.

count = 100

#Finally, keep track of heads and tails:

heads = 0
tails = 0

#They're zero because you haven't flipped the coin yet.

#Now, let's flip the coin (PROCESS).

while count != 0:
#each time through the loop, flip will randomly choose a side of the coin
flip = random.choice(coin)
#if/else selection. There are only two choices.
if flip == "heads":
heads += 1
else:
tails += 1
#decrement the counter, or you'll be in an infinite loop
#it started at 100, so subtract one each iteration
count -= 1

#Finally, let's print the OUTPUT:
print "Heads: ", heads
print "Tails: ", tails

Not the indentation after the while loop line.
That's a Python thing.

Since I've put so much time into this tutorial, I have a
challenge for you: Write a program that rolls a pair of
ten-sided dice, and tell me what the outcome of the roll is?
How about the outcome of three rolls?

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PyCon 2009 (US) - Call for Tutorials

2008-10-01 Thread Greg Lindstrom
The period for submitting tutorial proposals for Pycon 2009 (US) is open and
will continue through Friday, October 31th. This year features two
"pre-conference" days devoted to tutorials on Wednesday March 25 & Thursday
March 26 in Chicago. This allows for more classes than ever.

Tutorials are 3-hours long on a specific topic of your choice. Last year we
featured classes on Learning Python, Web Development, Scientific Computing,
and many more. Class size varied from 10 to over 60 students. The extended
time spent in class allows teachers to cover a lot of material while
allowing for interaction with students.

The full Call for Tutorial Proposals, including submission details, an
example proposal as well as a template, is available at <
http://us.pycon.org/2009/tutorials/proposals/>.

Tutorial selections will be announced in early December to give you time to
prepare your class and PyCon will compensate instructors US$1,500 per
tutorial.

If you have any questions, please contact [EMAIL PROTECTED]

Greg Lindstrom
Tutorial Coordinator, PyCon 2009 (US)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unable to import Image module from my application

2008-10-01 Thread Emile van Sebille

ShivKumar Anand wrote:

I am using Python Image library on windows and it is running well.
 
I am using RHEL E4 on another machine and when I installed 
"python-imaging-1.1.6-2.el4.rf.i386.rpm", still i am not able to call 
the Image and ImagOps modules from my application on this Linux machine.
 
After that --I manually added Imaging1.1.4 folder in 
/usr/lib/Python2.4/site-packages and added entry in easy_install.pth.
After that, I am able to import the modules from python prompt, but 
still I am not able to import from my application.


It's likely you've still got a path issue.  When you import from the 
command line the contents of your current directory is importable.  I'd 
suspect you were in the PIL directory when you tested from the command line.


To verify a path problem, add
sys.path.append('/usr/lib/Python2.4/site-packages//usr/lib/Python2.4/site-packages')
prior to the import in your application.  If that works, double check 
your path setup.


HTH,

Emile


 
I am not able to figure out the exact reason for this.
 
 
Kindly guiide me.

Thanks in anticipation.
 
 
Shiv



MSN Technology brings you the latest on gadgets, gizmos and the new hits 
in the gaming market. Try it now! 





___
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] Idle and windows XP firewall

2008-10-01 Thread David Holland
The program does not start up.  I think it is a firewall issue but I am having 
problems changing my firewall to allow idle.

--- On Wed, 1/10/08, Kent Johnson <[EMAIL PROTECTED]> wrote:
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Idle and windows XP firewall
To: [EMAIL PROTECTED]
Date: Wednesday, 1 October, 2008, 11:35 AM

On Wed, Oct 1, 2008 at 5:04 AM, David Holland <[EMAIL PROTECTED]>
wrote:
> At work I have windows XP service pack 3 and although I have sys admin I
can
> not use idle.
> I have googled but no success - any ideas?

What problem are you having?



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


Re: [Tutor] Idle and windows XP firewall

2008-10-01 Thread W W
Why would your firewall be blocking idle? Does idle connect to the internet?

On Wed, Oct 1, 2008 at 8:21 AM, David Holland <[EMAIL PROTECTED]>wrote:

> The program does not start up.  I think it is a firewall issue but I am
> having problems changing my firewall to allow idle.
>
> --- On *Wed, 1/10/08, Kent Johnson <[EMAIL PROTECTED]>* wrote:
>
> From: Kent Johnson <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Idle and windows XP firewall
> To: [EMAIL PROTECTED]
> Date: Wednesday, 1 October, 2008, 11:35 AM
>
> On Wed, Oct 1, 2008 at 5:04 AM, David Holland <[EMAIL PROTECTED]>
> wrote:
> > At work I have windows XP service pack 3 and although I have sys admin I
> can
> > not use idle.
> > I have googled but no success - any ideas?
>
> What problem are you having?
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Text Scatter Plots?

2008-10-01 Thread R. Alan Monroe
> Is there a text graphics module that does say scatter plots or
> histograms? I'm thinking of stuff prior to the graphics era of
> computing. I'm looking for something really simple.

Here's a quick and dirty way to do basic histogram of dice rolls:


import random

rolls={}

for x in range(1):
a = [random.randint(1,10) for x in range(2)]
v = sum(a)

try:
rolls[v] += 1
except KeyError:
rolls[v] = 1

m = max(rolls.values())
stretch = (m/70.0)

for x in rolls.keys():
print x, rolls[x], '*' * ( int(rolls[x] / stretch)  )

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


Re: [Tutor] Idle and windows XP firewall

2008-10-01 Thread Lie Ryan
On W W wrote:
> 
> Message: 6
> Date: Wed, 1 Oct 2008 08:46:50 -0500
> From: "W W" <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Idle and windows XP firewall
> To: [EMAIL PROTECTED]
> Cc: tutor python 
> Message-ID:
> <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Why would your firewall be blocking idle? Does idle connect to the
> internet?

No, but since IDLE itself is written in Python, it use a really weird
way to communicate with the python process. I don't know the details of
that really weird way, but it involves the possibility of a firewall
blocking IDLE. The safe way if you can't configure firewall is to open
IDLE without subprocess.

> On Wed, Oct 1, 2008 at 8:21 AM, David Holland
> <[EMAIL PROTECTED]>wrote:

(snip)
> >
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> 
> 
> -- 
> To be considered stupid and to be told so is more painful than being
> called
> gluttonous, mendacious, violent, lascivious, lazy, cowardly: every
> weakness,
> every vice, has found its defenders, its rhetoric, its ennoblement and
> exaltation, but stupidity hasn't. - Primo Levi
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> <http://mail.python.org/pipermail/tutor/attachments/20081001/1dc0aa03/attachment.htm>
> 
> --
> 

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


Re: [Tutor] unable to import Image module from my application

2008-10-01 Thread Emile van Sebille

Emile van Sebille wrote:

To verify a path problem, add
sys.path.append('/usr/lib/Python2.4/site-packages//usr/lib/Python2.4/site-packages') 


erhhmmm...

sys.path.append('/usr/lib/Python2.4/site-packages/Imaging1.1.4')

EvS

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


[Tutor] sample python twill scripts?

2008-10-01 Thread jeremiah
Just wondering if anyone here would be interested in sharing a python
twill script?  I'd just like to take a gander at how others are
engineering their scripts.

Thanks,
JJ



Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.


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


Re: [Tutor] Idle and windows XP firewall

2008-10-01 Thread Alan Gauld


"W W" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Why would your firewall be blocking idle? Does idle connect to the 
internet?


It connects to itself via a socket. But I thought that problem had 
been fixed

several releases ago...

On Wed, Oct 1, 2008 at 8:21 AM, David Holland 
<[EMAIL PROTECTED]>wrote:


The program does not start up.  I think it is a firewall issue but 
I am

having problems changing my firewall to allow idle.


Which version of Python are you using?

Alan G. 



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


Re: [Tutor] python: can't open file 'test.py' : [Errno 2] No such file or directory

2008-10-01 Thread Pierre Dagenais


If you're right about having to give the full path, and I suspect you 
are, Then this means that python knows to search the currennt working 
directory for  the file to execute, but nowhere else.


Correct, just like every other program.
If you run notepad foo.txt notepad will open a new foo.txt
in the current folder it will not search your drive to find some
other foo.txt that you created prevbiously.
Why would python be any different?
I didn't realize other program were also behaving that way, I don't work 
much with the command prompt anymore :-)


The trick to do what you want is not to execute python but
to execute the script and allow the OS to associate Python
with it.

That is what I was missing, C:\test.py will execute.


So either just type the script name into the prompt (assuming
it is on the PATH) or double click in explorer and Windows will
find Python itself.

HTH,

It sure does, thanks everybody for the great replies,
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2008-10-01 Thread Pierre Dagenais

kayla bishop wrote:
ok i imported the random module and set it up with a 2... i can't get it to loop correctly to where it keeps going until the total of heads and tails is 100> Date: Wed, 1 Oct 2008 00:18:51 -0400> From: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] (no subject)> > kayla bishop wrote:> > I can't figure out how to write a program where you flip a coin 100 times and it keeps track of how many heads and tails you flipped but it has to be random. Can you please help> > 

Hi Kayla,
Have you read the other posts on the list? bhaaluu sent you a great 
little tutorial showing how a pro would go about solving this problem. 
Read it carefully, it's really worth all the time you will spend on it. 
Your problem seems to be that you expect the random module to return a 
100 answers, it won't. Random returns only one choice for everytime you 
run it. That's why we use a loop, to run random a 100 times.
Don't despair, in the beginning everybody trips on silly details like 
that, keep at it and soon you'll be the expert.


Kent,
I didn't realize the list had a policy, I'm sorry for breaking it. Were 
can I read it? ignorance not being an excuse.

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


Re: [Tutor] (no subject)

2008-10-01 Thread bhaaluu
Correction of post typo follows.

On Wed, Oct 1, 2008 at 8:57 AM, bhaaluu <[EMAIL PROTECTED]> wrote:
>
> #Now, let's flip the coin (PROCESS).
>
> while count != 0:
>#each time through the loop, flip will randomly choose a side of the coin
>flip = random.choice(coin)
>#if/else selection. There are only two choices.
>if flip == "heads":
>heads += 1
>else:
>tails += 1
>#decrement the counter, or you'll be in an infinite loop
>#it started at 100, so subtract one each iteration
>count -= 1
>
> Not the indentation after the while loop line.
> That's a Python thing.

That should be "NOTE the indentation after the while loop".
Also note the indentation after the if and else lines. Python
uses indentation to define 'blocks' of code. Another little
detail that may escape one's notice is that the first line
of each block ends with a colon. A block is finished when
the indentation ends. Blocks of code may be nested
within each other, as long as they are properly indented.

>
> Since I've put so much time into this tutorial, I have a
> challenge for you: Write a program that rolls a pair of
> ten-sided dice, and tell me what the outcome of the roll is?
> How about the outcome of three rolls?
>

The programming challenge still stands! Kayla? (BTW, when
I say "tell me what the outcome is", I'm asking for your program
to produce some OUTPUT!)

Happy [Python] Programming!
-- 
b h a a l u u at g m a i l dot c o m
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Finding the "streaks" in heads/tails list

2008-10-01 Thread Alec Henriksen
Hello,

I thought it'd be cool to write a program for my logic/critical thinking
class, and right now we're evaluating randomness - and the deception of
it. A previous post inspired it - coin flipping.

So, I've written a program that flips a coin 1000 times and records it
all in a dictionary, like this:

# 0 = heads, 1 = tails
flips = [0,0,0,1,0,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1]

What I want to do, is find out the largest "streak" of digits. In the
above example, the streak would be 5, because there are 5 tails flips in
a row.

I've thought about this, and it seems like regular expressions would be
needed.

Can someone help/hint? Thanks in advance!


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


Re: [Tutor] (no subject)

2008-10-01 Thread Kent Johnson
On Wed, Oct 1, 2008 at 4:15 PM, Pierre Dagenais <[EMAIL PROTECTED]> wrote:

> I didn't realize the list had a policy, I'm sorry for breaking it. Were can
> I read it? ignorance not being an excuse.

Hmm, it doesn't seem to be written down. I'll have to add it to the
list info page and the welcome message.

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


Re: [Tutor] Finding the "streaks" in heads/tails list

2008-10-01 Thread Kent Johnson
On Wed, Oct 1, 2008 at 4:56 PM, Alec Henriksen <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I thought it'd be cool to write a program for my logic/critical thinking
> class, and right now we're evaluating randomness - and the deception of
> it. A previous post inspired it - coin flipping.
>
> So, I've written a program that flips a coin 1000 times and records it
> all in a dictionary, like this:
>
> # 0 = heads, 1 = tails
> flips = [0,0,0,1,0,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1]
>
> What I want to do, is find out the largest "streak" of digits. In the
> above example, the streak would be 5, because there are 5 tails flips in
> a row.
>
> I've thought about this, and it seems like regular expressions would be
> needed.

Regular expressions are for processing strings, not loops.

I would loop through the list with a for loop, keeping track of the
last value seen and the current count. If the current value is the
same as the last, increment the count; if it is different, reset the
count.

You don't actually have to put the flips into a list, you could count
the runs directly as you make the flips.

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


[Tutor] newbee needs direction

2008-10-01 Thread Michael yaV
Here is my problem and my coding knowledge consists of html. I have  
all the time in the world to play with this so I thought I would at  
least ask how to get started.
I want to create a web base program that would output team standings.  
The only given will be the names of each team and their division (ie:  
division 1, division 2). What will be supplied is the score of an  
event (game played between 2 teams), and weather it is a division game  
(two teams in the same division playing each other) or out of division  
game (two teams in different divisions playing each other). The out- 
put will then be, the team with the highest percent of winnings will  
show up at the top of a list and the worst win/loss percentage team  
will show up at the bottom of a list. Also, for out-put, their will be  
a total of 7 columns beside each team name. 4 columns for Division  
play, a win column, a loss column, a tie column and then the win/loss  
percentage column. then their will be 3 columns for Non-Division play,  
a win column, a loss column, a tie column.
So, based on an entered score, a number will be added to one of the  
columns, the win column, loss column or tie column and will also be  
used to compute a win/loss percentage. The win loss percentage will be  
total games won, divided by total games played (ie: A team that is 3-2  
has a .600 win percentage because 3 divided by five equals .600). For  
ties you would have to Add up the number of wins and half the number  
of ties, and divide by the total number of games played. (ie: For  
instance, a team with a 10-5-1 record would have a 10.5/16 or .656  
winning percentage). If a team plays in a non-division game it will  
have no barring to the standings unless their are two or more teams  
with the same record. Therefore, if 2 teams have the same division  
wins (win/loss percentage) but one team has more non-division wins,  
that team should show up higher on the list.
I would also like that all teams' scores would have to be added before  
a standings change would be calculated and made week to week. However,  
their might have to be a "bye" button or just add zeros, in case a  
particular team does in fact have a bye while other teams play. Also,  
this way I will know which teams need their scores to be added.
I will most likely be adding the scores to an admin page and the  
results will them be posted on a website.

OK... how should I get started and how tough will this be?

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


Re: [Tutor] Finding the "streaks" in heads/tails list

2008-10-01 Thread Danny Yoo
> Regular expressions are for processing strings, not loops.

>From a theoretical point of view, this isn't quite true: regular
expressions can deal with sequences of things.  It's true that most
regular expression libraries know how to deal only with characters,
but that's a matter of specializing the library for efficiency, and
not a general property of regexes.

But what regular expressions (i.e. finite-state automata) can't do
very well is count with memory, and the task you're asking for is
fundamentally an anti-regexp one.


> I would loop through the list with a for loop, keeping track of the
> last value seen and the current count. If the current value is the
> same as the last, increment the count; if it is different, reset the
> count.

Agreed.  This seems direct.

If we want to be cute, we can also use the itertools.groupby()
function to do the clumping of identical sequential values for us.
For example:

#
>>> for group in itertools.groupby('caaabcc'):
... print group[0], len(list(group[1]))
...
a 4
b 4
c 1
a 3
b 1
a 4
c 2
#

See the standard library documentation for more details on itertools.groupby():

http://www.python.org/doc/lib/itertools-functions.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding the "streaks" in heads/tails list

2008-10-01 Thread Kent Johnson
On Wed, Oct 1, 2008 at 6:00 PM, Danny Yoo <[EMAIL PROTECTED]> wrote:
>> Regular expressions are for processing strings, not loops.
>
> From a theoretical point of view, this isn't quite true: regular
> expressions can deal with sequences of things.

Sheesh! OK, *Python* regular expressions are for processing strings :-)

> If we want to be cute, we can also use the itertools.groupby()
> function to do the clumping of identical sequential values for us.
> For example:
>
> #
 for group in itertools.groupby('caaabcc'):
> ... print group[0], len(list(group[1]))

Hmm, I smell a one-liner here:
max(len(list(group[1])) for group in itertools.groupby('caaabcc'))

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


Re: [Tutor] Finding the "streaks" in heads/tails list

2008-10-01 Thread Alan Gauld


"Kent Johnson" <[EMAIL PROTECTED]> wrote

What I want to do, is find out the largest "streak" of digits. In 
the
above example, the streak would be 5, because there are 5 tails 
flips in

a row.



I would loop through the list with a for loop, keeping track of the
last value seen and the current count. If the current value is the
same as the last, increment the count; if it is different, reset the
count.


You need to store the count before resetting it since you want
to know the largest value of count over the list. Or at least keep a
separate max variable that you update if count > max.

But as Kent also said the easiest way is probably to just track the
runs and their count as the data is generated rather than waiting
till the end and post-processing the results.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] newbee needs direction

2008-10-01 Thread Alan Gauld

"Michael yaV" <[EMAIL PROTECTED]> wrote


Here is my problem and my coding knowledge consists of html.


OK, The first step is to pause your project long enough to learn
the basics of programming - with Python since you are asking
on a Python list! :-)

I want to create a web base program that would output team 
standings.


The second stage is to write the program as a non web
application first. Keeping the novelty factors down helps
when learning to program!

The only given will be the names of each team and their division 
(ie:  division 1, division 2). What will be supplied is the score of 
an  event (game played between 2 teams), and weather it is a 
division game  (two teams in the same division playing each other) 
or out of division  game (two teams in different divisions playing 
each other).


Sounds OK so far.

The output will then be, the team with the highest percent of 
winnings will  show up at the top of a list and the worst win/loss 
percentage team  will show up at the bottom of a list. Also, for 
out-put, their will be  a total of 7 columns beside each team name. 
4 columns for Division  play, a win column, a loss column, a tie 
column and then the win/loss  percentage column. then their will be 
3 columns for Non-Division play,  a win column, a loss column, a tie 
column.


A good idea when trying to define this kind of thing is to produce
a sample output form - in html since you know it already.

< lots more snipped>

OK... how should I get started and how tough will this be?


Its a pretty good aspirational beginners project.
Not too hard for a newbie and easy enough to chunk up into bite
sized morsels.

But first focus on getting the basics of Python programming clear
because otherwise you will wind up getting the details of your
problem all mixed up with the details of Python! Stick to solving
one problem at a time, so take a week or so out to learn Python 
basics.

Then go back to the problem and focus on building a command
line solution first. Once thats done its relatively easy to convert
it for the web.

For learning Python pick one of the Non Programmers tutorials
on the Python web site and follow it through.
[ If you pick mine to only need to go as far as the end of the
 Basics section before returning to your problem...]

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] newbee needs direction

2008-10-01 Thread Michael Waltemeyer

Thanks Alan.
On Oct 1, 2008, at 8:37 PM, Alan Gauld wrote:


"Michael yaV" <[EMAIL PROTECTED]> wrote


Here is my problem and my coding knowledge consists of html.


OK, The first step is to pause your project long enough to learn
the basics of programming - with Python since you are asking
on a Python list! :-)


I want to create a web base program that would output team standings.


The second stage is to write the program as a non web
application first. Keeping the novelty factors down helps
when learning to program!

The only given will be the names of each team and their division (ie: 
 division 1, division 2). What will be supplied is the score of an  
event (game played between 2 teams), and weather it is a division 
game  (two teams in the same division playing each other) or out of 
division  game (two teams in different divisions playing each other).


Sounds OK so far.

The output will then be, the team with the highest percent of 
winnings will  show up at the top of a list and the worst win/loss 
percentage team  will show up at the bottom of a list. Also, for 
out-put, their will be  a total of 7 columns beside each team name. 4 
columns for Division  play, a win column, a loss column, a tie column 
and then the win/loss  percentage column. then their will be 3 
columns for Non-Division play,  a win column, a loss column, a tie 
column.


A good idea when trying to define this kind of thing is to produce
a sample output form - in html since you know it already.

< lots more snipped>

OK... how should I get started and how tough will this be?


Its a pretty good aspirational beginners project.
Not too hard for a newbie and easy enough to chunk up into bite
sized morsels.

But first focus on getting the basics of Python programming clear
because otherwise you will wind up getting the details of your
problem all mixed up with the details of Python! Stick to solving
one problem at a time, so take a week or so out to learn Python basics.
Then go back to the problem and focus on building a command
line solution first. Once thats done its relatively easy to convert
it for the web.

For learning Python pick one of the Non Programmers tutorials
on the Python web site and follow it through.
[ If you pick mine to only need to go as far as the end of the
 Basics section before returning to your problem...]

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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



Michael Waltemeyer (yaVarsity)
[EMAIL PROTECTED]

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