Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Nithya Nisha
Hi there,

This is the Code. Please check it.It is working fine.

>>>import random
>>>headsCount = 0
>>>tailsCount = 0
>>>count = 1
>>>
>>>while count <= 100:
>>>   coin = random.randrange(2)
>>>   if coin == 0:
>>> headsCount += 1
>>>   else:
>>> tailsCount += 1
>>>   count += 1
>>>
>>>print "The number of heads was", headsCount
>>>print "The number of tails was", tailsCount
>>>
>>>raw_input("\n\nPress the enter key to exit.")


*
Your Description *:

On Tue, Nov 16, 2010 at 1:25 PM, Dave Angel  wrote:

> When I run this code (I'm also a noob) I get this result:-
>>
>>  [evaluate lines 1-22 from untitled-1.py]
>
 The number of heads was 73
>> The number of tails was 100
>>
>> Press the enter key to exit.
>>
>> # Surely, if flipping a single coin 100 times your total number of heads
>> and
>> tails should add up to 100
>> # not 173 or am I missing the point?
>>
>>
>>  No, you're missing an indentation.  If you check the code you're running,
> I think you'll find that you didn't unindent the line incrementing count.
>
> Of course, it's less error prone to simply use
> for count in xrange(100):
>
> instead of while count < 100:
>
> and you wouldn't need to increment count.
>
> DaveA
>
>


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


Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Luke Pettit
Arrr thats better Nithya it works fine now. I had it working fine before it
was just coming up with that strange result of 73 and 100
when I copied the code into wing to check it out in order to understand it.
Wing picked up the spacing and I had already corrected
that Dave as I was simply looking at Nithya code.

On 16 November 2010 19:10, Nithya Nisha  wrote:

> Hi there,
>
> This is the Code. Please check it.It is working fine.
>
> >>>import random
> >>>headsCount = 0
> >>>tailsCount = 0
> >>>count = 1
> >>>
> >>>while count <= 100:
> >>>   coin = random.randrange(2)
> >>>   if coin == 0:
> >>> headsCount += 1
> >>>   else:
> >>> tailsCount += 1
> >>>   count += 1
> >>>
> >>>print "The number of heads was", headsCount
> >>>print "The number of tails was", tailsCount
> >>>
> >>>raw_input("\n\nPress the enter key to exit.")
>
>
> 
> *
> Your Description *:
>
> On Tue, Nov 16, 2010 at 1:25 PM, Dave Angel  wrote:
>
>>  When I run this code (I'm also a noob) I get this result:-
>>>
>>>  [evaluate lines 1-22 from untitled-1.py]
>>
> The number of heads was 73
>>> The number of tails was 100
>>>
>>> Press the enter key to exit.
>>>
>>> # Surely, if flipping a single coin 100 times your total number of heads
>>> and
>>> tails should add up to 100
>>> # not 173 or am I missing the point?
>>>
>>>
>>>  No, you're missing an indentation.  If you check the code you're
>> running, I think you'll find that you didn't unindent the line incrementing
>> count.
>>
>> Of course, it's less error prone to simply use
>> for count in xrange(100):
>>
>> instead of while count < 100:
>>
>> and you wouldn't need to increment count.
>>
>> DaveA
>>
>>
>
>
> --
> With Regards,
> Nithya S
>
>


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


Re: [Tutor] new turtle module

2010-11-16 Thread roberto
On Fri, Oct 8, 2010 at 1:11 AM, Alan Gauld  wrote:
>
> "roberto"  wrote
>
>> is it correct to overwrite the turtle.py and turtle.pyc files
>
> I'd overwrite the .py file but get Python to generate a new .pyc for you
> just to ensure compatibility.
>
> just type import turtle at the >>> prompt.
>

thanks it works

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


Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Nithya Nisha
Thankyou..!!!


Regards,
Nithya

On Tue, Nov 16, 2010 at 1:51 PM, Luke Pettit  wrote:

> Arrr thats better Nithya it works fine now. I had it working fine before
> it was just coming up with that strange result of 73 and 100
> when I copied the code into wing to check it out in order to understand it.
> Wing picked up the spacing and I had already corrected
> that Dave as I was simply looking at Nithya code.
>
>
> On 16 November 2010 19:10, Nithya Nisha  wrote:
>
>> Hi there,
>>
>> This is the Code. Please check it.It is working fine.
>>
>> >>>import random
>> >>>headsCount = 0
>> >>>tailsCount = 0
>> >>>count = 1
>> >>>
>> >>>while count <= 100:
>> >>>   coin = random.randrange(2)
>> >>>   if coin == 0:
>> >>> headsCount += 1
>> >>>   else:
>> >>> tailsCount += 1
>> >>>   count += 1
>> >>>
>> >>>print "The number of heads was", headsCount
>> >>>print "The number of tails was", tailsCount
>> >>>
>> >>>raw_input("\n\nPress the enter key to exit.")
>>
>>
>> 
>> *
>> Your Description *:
>>
>> On Tue, Nov 16, 2010 at 1:25 PM, Dave Angel  wrote:
>>
>>>  When I run this code (I'm also a noob) I get this result:-

  [evaluate lines 1-22 from untitled-1.py]
>>>
>> The number of heads was 73
 The number of tails was 100

 Press the enter key to exit.

 # Surely, if flipping a single coin 100 times your total number of heads
 and
 tails should add up to 100
 # not 173 or am I missing the point?


  No, you're missing an indentation.  If you check the code you're
>>> running, I think you'll find that you didn't unindent the line incrementing
>>> count.
>>>
>>> Of course, it's less error prone to simply use
>>> for count in xrange(100):
>>>
>>> instead of while count < 100:
>>>
>>> and you wouldn't need to increment count.
>>>
>>> DaveA
>>>
>>>
>>
>>
>> --
>> With Regards,
>> Nithya S
>>
>>
>
>
> --
> Luke Pettit
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] program hangs in while loop using wx.yield

2010-11-16 Thread Patty
Hi Terry - I am an alumni of UCSC (University of California, Santa Cruz) and 
live really close so I can request books throughout the UC system just like 
you describe and there is no limit - or maybe an extremely high limit - to 
the number of books I can check out from McHenry Library.  It is so worth 
paying alumni dues!  There is no way they would transport books to the 
public library to make it easier for people though - not with the way the 
city and the university feel about each other  :}


And discounts on courses through the University Extension program.  That is 
how I found out about - and took - the online Python for Programmers course. 
Though I wasn't really happy with it and went on to listen to the Google 
website video - that guy was very clear and helpful I forgot his name.  And 
then I went through Alan Gauld's tutorial which also helped.


By coincidence I am still working on my own function where I want to display 
a picture and some text and have a timer so that it stays on screen for a 
specific amount of time and then I go on to close that out and redraw the 
screen.  I am working with the Tkinter documentation and trying to 
understand.  I tried a couple tests just adding a few lines to my own 
program that didn't accomplish exactly what I want, so planning to type in 
very simple examples from the doc, observe that and then go back to my own 
code.


If I just can't figure out how to do this with Tkinter and the Python 
Imaging Library, is 'wxPython' the additional software I would want to 
install and try with?  Is its purpose to make GUI event programming easier 
(that would mean the defaults provided are difficult, right? So I shouldn't 
feel bad about being confused?)  If so, can someone explain these additional 
software packages out there?  I mean are they coming from some third 
companies?  And why?  If the software is free.  I'm not understanding the 
history or business part of these Python modules and libraries.  Isn't there 
one organization who is discussing or approving standards for this language?


Regards,

Patty

- Original Message - 
From: "Terry Carroll" 

To: 
Sent: Monday, November 15, 2010 11:37 PM
Subject: Re: [Tutor] program hangs in while loop using wx.yield



On Sun, 14 Nov 2010, Alex Hall wrote:


Is there a basic tutorial for this sort of thing?


Chapter 3 ("Working in an event-driven environment") of the book "wxPython 
in Action" is a pretty good tutorial on event-driven GUI programming in 
wxPython.  The book in general is pretty good; I no longer buy many 
computer books, but this one was worth it.


If you don't want to buy it, if you're in the U.S., you can go to 
http://www.worldcat.org/oclc/67122432 and plug in your zip code to see if 
a library near you[1] has it.


[1] or a library that has inter-library loan arrangements with a library 
near you.  I'm currently reading "Essential SQLAlchemy," courtesy of the 
San Diego State University library.  My local library (San Jose Public 
Library) borrowed it from SDSU and then lent it to me.  It's kind of cool 
that one library will send a book 400 miles to another, just because I'm 
too cheap to buy a copy and asked for it.


Apologies to anyone at SDSU who's learning SQLAlchemy and wondering why 
they can't find this book in their library.

___
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


[Tutor] wxPython, Tkinter (was: program hangs in while loop using wx.yield

2010-11-16 Thread Terry Carroll

On Tue, 16 Nov 2010, Patty wrote:

Hi Terry - I am an alumni of UCSC (University of California, Santa Cruz) 
and live really close so I can request books throughout the UC system 
just like you describe and there is no limit - or maybe an extremely 
high limit - to the number of books I can check out from McHenry 
Library.  It is so worth paying alumni dues!  There is no way they would 
transport books to the public library to make it easier for people 
though - not with the way the city and the university feel about each 
other :}


You might be surprised.  I would't have expected to get a book from San 
Diego State University sent to the San Jose Public Library, but it did. 
I just entered teh request, and a few hours later, I had anote saying it 
was on the way.  The system finds the copy and obtains it.


It's not on a one-to-one basis, i.e., as if SJPL had an arrangement with 
SDSU; it's more of the libraries deciding to patricipate in the pool.


If I just can't figure out how to do this with Tkinter and the Python Imaging 
Library, is 'wxPython' the additional software I would want to install and 
try with?


wxPython is an alternative to Tkinter.  The advantage of Tkinter is that 
it comes as part of standard Python.  You know that it will be installed 
on any reasonably current Python installation.  If you write a program 
using Tkinter and send it to me, you can be sure that I can run it as long 
as I have Python installed (at least as far as the GUI is concerned; other 
things such as PIL might still be an issue).


wxPython is an API over the cross-platform wxWidgets GUI.  I think it 
provides a cleaner and more native look compared to Tkinter. For what my 
opinion is work (and that's not much -- I'm pretty inexperienced at GUI 
stuff), I find it at least as easy to use as Tkinter, but I recall a 
learning curve when I started.


I don't use Tkinter any more, preferring wxPython, but opinions will vary.

Here's a comparison of the two; it's hosted on a wxPython site, so it's 
undoubtedly slanted toward wxPython:

http://wiki.wxpython.org/Choosing%20wxPython%20over%20Tkinter

Another couple:
http://www.llaisdy.com/static/tech/python/calc.html
http://ojs.pythonpapers.org/index.php/tpp/article/viewArticle/61

However, if you would like an example of using Tkinter with PIL, I would 
be happy to provide you with a very rough program I wrote several years 
ago for my own use (when I still used Tkinter).  It loads an image that 
was taken with a digital camera; reads the date the photo was taken from 
the image's EXIF data; adds a timestamp to the photo, and saves it.


It's very rough; I have the habit of writing something only to the point 
where it's good enough for me, and then stop development on it.  But you 
might find it helpful of a straightforward program that uses both.  It's 
from about 2006 or so, and I am by no means a GUI programming expert and 
was even less so then, so my techniques may be suspect; but I'd be happy 
to send it to you for what it's worth.

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


Re: [Tutor] program hangs in while loop using wx.yield

2010-11-16 Thread Walter Prins
Not wanting to hijack Terry's conversation, but for what it's worth:

On 16 November 2010 18:08, Patty  wrote:

> If I just can't figure out how to do this with Tkinter and the Python
> Imaging Library, is 'wxPython' the additional software I would want to
> install and try with?  Is its purpose to make GUI event programming easier
> (that would mean the defaults provided are difficult, right? So I shouldn't
> feel bad about being confused?)  If so, can someone explain these additional
> software packages out there?  I mean are they coming from some third
> companies?  And why?  If the software is free.  I'm not understanding the
> history or business part of these Python modules and libraries.  Isn't there
> one organization who is discussing or approving standards for this language?
>

wxPython is a set of Python wrappers for the wxWidgets GUI component set.
wxWidgets in turn is a set of C++ GUI wrapper controls that wraps the native
GUI controls (e.g. edit boxes, memo boxes, drop downs, buttons, radio
buttons, checkboxes, menu's and so on)  on various platforms.

Hence it thus provides a common set of classes/components/controls and
effectively a common API for writing GUI based applications in a cross
platform fashion, e.g. that target multiple platforms (e.g. Mac, Windows,
Unix, Linux etc.)   So, by using wxPython you can write applications knowing
that your app should work pretty much unmodified on any system where
wxWidgets is available/installed.

wxWidgets as well as wxPython is open source, so the source is freely
available and managed/supported by their respective development teams.   For
more see:
http://www.wxwidgets.org/about/
http://www.wxpython.org/what.php

You can download and install wxPython for Windows here (make sure to get the
one corresponding to the version of Python that you have installed.):
http://www.wxpython.org/download.php#stable

You should also install the demo application and documentation.  The demo
application will give you an idea of what you can do and how to do it.

As an aside, there are other similar (competing) libraries that one might
use, e.g. GTK or QT for example (or for that matter TK), which needless to
say also have Python wrappers.  Which to use is largely a matter of context
and taste, but suffice it to say wx is not a bad choice.  It's however quite
large, so don't expect it to all sink in overnight. (I certainly am no wx
expert, I just know enough to be dangerous ;) )

As for Event driven programming, it takes a little getting used to if you're
only used to normal "straight line" programs at this point, GUI programming
adds its own set up of detail and complexity on top of the event-driven
programming model (not least that it usually demands a relatively solid
understanding of OO concepts), so don't feel bad if you're feeling
confused.  (You might want to read up/google "Event driven programming" and
do some research and come back with more questions after you've tried a few
things yourself.)

That's my £0.01 worth anyway,

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


Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-16 Thread Stephanie Dawn Samson

Greetings,
As a thread starter, I thought I should write the rewritten code I got that 
others helped me get to, since this thread is still going on.

# Coin Flips# The program flips a coin 100 times and then# tells you the number 
of heads and tailsimport random
print "\a"print "\tWelcome to 'Coin Flipper!'"print "\nI will flip a coin 100 
times and then tell you"print "the number of heads and tails!\n"
# set the coinheadsCount = 0tailsCount = 0count = 1
while count <= 100:coin = random.randrange(2)if coin == 0:
headsCount += 1else:tailsCount += 1count += 1

print "The number of heads was", headsCountprint "The number of tails was", 
tailsCount
raw_input("\n\nPress the enter key to exit.")
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] program hangs in while loop using wx.yield

2010-11-16 Thread Alan Gauld


"Patty"  wrote


then I went through Alan Gauld's tutorial which also helped.


Glad to hear it :-)

If I just can't figure out how to do this with Tkinter and the 
Python


I can send some basic code if that would help...


Imaging Library, is 'wxPython' the additional software I would want 
to install and try with?  Is its purpose to make GUI event 
programming easier


No, in fact it is similar in concept to Tkinter but works in a style 
more
like most other GUI toolkits. It is also far more powerful with more 
widgets

and more complex styling tools and support for printing(as in paper).
Tkinter is catching up on the native look department through the new
ttk widgets but wxWidgets are nativbe from the ground up so they
will probably always look slightly more "natural".

But for your application wxPython and Tkinter should wind up looking
pretty much the same both in terms of code and end result,.

feel bad about being confused?)  If so, can someone explain these 
additional software packages out there?  I mean are they coming from 
some third companies?  And why?  If the software is free.  I'm not 
understanding the history or business part of these Python modules 
and libraries.


Open source works like this: Somebody finds they need somethjing built
so they build it. Then they think, maybe other people could use this,
so they announce its availability (usually after polishing it a bit,
adding some comments etc) Other people start using it, they ask for
extra features, or they add some themselves and send it to the author.
Gradually a core team of developers forms and they start publishing
regular updates and bug fixes.

It is all very organic and apparently disorganised but it works most 
of the time.

Code that isn't very good but serves a need gradually gets improved
- or eventually rewritten from scratch - and code that is not really 
needed

tends to just wither and die from lack of support. Some projects grow
into huge undertakings like GNU and Linux and OpenOffice etc.
These might be sponsored by large (or small) companies providing
their paid staff to contribute to the project because they find it 
critical

to their business (so they want to ensure it stays viable) or they see
strategic advantage - eg Sun's support for OpenmOffice as
an alternative to MS Office...

Most of Python and its modules come from such a background.

one organization who is discussing or approving standards for this 
language?


There is a community which is loosely organised and a process
for submitting changes etc. How it works varies from project to 
project.

You can see it all in action if you visit SourceForge the home of many
OpenSource projects both large and small. But there is nothing like
the formalised standards surrounding languages like C or COBOL
or Java.

HTH,


--
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] While Loops: Coin Flip Game :p:

2010-11-16 Thread Alan Gauld


"Stephanie Dawn Samson"  wrote

 thought I should write the rewritten code I got that others helped 
me get to


By applying a couple of other ideas that have been suggested you get
something shorter and arguably slightly clearer:

# Coin Flips
# The program flips a coin 100 times and then
# tells you the number of heads and tails

import random

print """
   Welcome to 'Coin Flipper!'
I will flip a coin 100 times and then tell you
the number of heads and tails!
"""
headsCount = 0

for count in range(100):
   if random.randrange(2):  # returns 1/0 => true/False
  headsCount += 1

print "The number of heads was", headsCount
print "The number of tails was", 100-headsCount
raw_input("\n\nPress the enter key to exit.")


And you could replace the whole for loop with a generator expression
if you really wanted to, but I suspect that is getting into advanced
territory for you at this stage...

HTH,


--
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] While Loops: Coin Flip Game :p:

2010-11-16 Thread bob gailer

Just for the heck of it:

heads = sum(random.randrange(2) for i in range(100))

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