Re: [Tutor] (no subject)

2009-09-13 Thread bhaaluu
Go for it! 8^D

On Sun, Sep 13, 2009 at 7:45 PM, shellc...@juno.com shellc...@juno.com wrote:
 I want to take two tuples and and print out all the elements in both tuples

 
 Best Weight Loss Program - Click Here!
 http://thirdpartyoffers.juno.com/TGL2141/fc/BLSrjpTFoYayK1TMy2HLJuXWZVUVwGcRz3BvRi27bhNCVhUuOvezC0KPl88/
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
b h a a l u u at g m a i l dot c o m
Gnu/Linux IS user-friendly.
It's NOT ignorant-friendly or idiot-friendly.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pygame

2009-07-20 Thread bhaaluu
Python Programming for the Absolute Beginner Second Edition.
Michael Dawson.
Boston, MA: Thomson Course Technology, 2006.
ISBN-13: 978-1-59863-112-8
ISBN-10: 1-59863-112-8

No experience required to learn Python programming.
This book will teach you the basics of Python programming
through simple game creation. You'll learn to:
Build, slice, and index strings.
Work with functions,
Read from and write to text files,
Create and manipulate sprites,
Tackle object-oriented programming,
Create a GUI,
and work sound, music, and create animation.

The book comes with a CD that has
Python 2.3.5
PyGame 1.6
LiveWires 2.0 --customized version for this book
Source code and projects from the book.

If you can make it through Dawson's book, you'll be prepared
to tackle PyGame tutorials such as:

Game Programming by Andy Harris (ISBN-13: 978-0-470-06822-9)
http://www.cs.iupui.edu/~aharris/pygame/

or

Beginning Game Development with Python and Pygame:
From Novice to Professional by Will McGugan (ISBN-13: 978-1590598726)

The PyGame site also has beginnner tutorials.
http://www.pygame.org/docs/

Look for Michael Dawson's book, and start programming text-based
games in Python from the very first chapter! By the end of the book,
you'll be programming 2D arcade-style games. (447 pages)

Hopefully helpful.
-- 
b h a a l u u at g m a i l dot c o m
Gnu/Linux IS user-friendly.
It's NOT ignorant-friendly or idiot-friendly.

On Mon, Jul 20, 2009 at 3:04 AM, Mazhar Hussainyam.m...@gmail.com wrote:
  Hello All! My name is Mazhar Hussain, and I am new to python, in fact, I am
 new to programming as a whole. I dont know if its the right list to talk
 about this.
  I am really interested in 2d games, especially 2d games. I am also
 interested in making games. I searched for a lot of programming languages
 but I didnt like anyone of them, either they were too hard to learn or not
 suitable to make games. But then I found Python. I had heard that it was
 very easy to learn and great for making games, it also had a binding for SDL
 called pygame. But the main games I want to create are: a pokemon clone, a
 megaman battle network clone and a world of goo like game. I just want to
 know if I can make these type of games with pygame(before learning python).
 If it can then I'll start learning python right away but if it cant then I
 think I may better find another language.

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


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


Re: [Tutor] Pygame

2009-07-20 Thread bhaaluu
On Mon, Jul 20, 2009 at 6:00 AM, Davidld...@gmx.net wrote:
 Mazhar,

 bhaaluu wrote:
 Python Programming for the Absolute Beginner Second Edition.
 Michael Dawson.
 Boston, MA: Thomson Course Technology, 2006.
 ISBN-13: 978-1-59863-112-8
 ISBN-10: 1-59863-112-8
 This is, in my judgment, a good suggestion, provided you are working on
 a Windows system. Otherwise some of the tools Dawson introduces will not
 work.
 So, start here, and move on to McGugan's book thereafter.

 David


I was able to work through Dawson's entire book on a Gnu/Linux system,
using X (Window system), Konsole, and the vim plain text editor.

Dawson uses a customized version of LiveWires towards the end of the book.
You must install the customized version for Dawson's examples to work
with Gnu/Linux.

I've worked through some of the source code for McGugan's book.
It seems to lean more towards 3D programming than 2D programming.
The Andy Harris book is geared to 2D programming in PyGame, and is
a good beginner introduction to PyGame.

You should already know some Python before reading Harris' book
because he doesn't really give a Python programming tutorial.
So, Dawson -- Harris -- McGugan is a good syllabus for Game
Programming in Python/PyGame.
-- 
b h a a l u u at g m a i l dot c o m
Gnu/Linux IS user-friendly.
It's NOT ignorant-friendly or idiot-friendly.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] GUI recommendations/tutorials?

2009-06-10 Thread bhaaluu
Have you looked at PyGame yet?
http://www.pygame.org/

On Wed, Jun 10, 2009 at 12:05 PM, taseriantaser...@gmail.com wrote:
 I think I'm ready to start working with some simple graphic output.
 Currently, I've got the basics of a Python program that calculates full
 tours of a honeycomb structure, going through each cell exactly once. The
 output from the program shows the paths as coordinates of each cell; what
 I'd like to do is create a simple window that would show the tour in
 graphical format, and using keystrokes to go through all of the tours that
 have been collected. I'm already accounting for eliminating duplicates by
 rotational symmetry by restricting the starting point to the cells in the
 northernmost row of hexes, but the ending point to be any of the edge
 hexes. I'm trying to identify duplicates by reflexive symmetries as well,
 but I'd like to get the visualization component up first.

 My problem is that I have no GUI experience outside of Visual Studio-style
 drag-and-drop IDEs. Which Python GUI system would you recommend for
 neophytes that would allow line drawing and a simple graphic load of a
 honeycomb structure in a JPG, for example, as a background?

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





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


Re: [Tutor] Find a good linux distribution with python.

2009-05-24 Thread bhaaluu
On Sun, May 24, 2009 at 4:02 PM, Michael Bernhard Arp Sørensen
mich...@arpsorensen.dk wrote:

 What distro do you run?


Debian GNU/Linux


 Another point: There's so many modules on the Internet, that it's difficult
 to get some sort of overview. That's why a distro is such a great idea
 because so many packages with python stuff is included. Could you get any
 kind of overview over python modules/libs other than a repo in a distro?


Like anything else that is huge, just tackle the parts of it that you need.


 I have concluded that there's no such thing as a perfect distro. Only some
 distros come close to perfection. In that case I was wondering if I should
 create my own python repo to set up a good working environment for
 development. That way I could use any distro. On the other hand, any code I
 migth write would be difficult for others to use.

 Any ideas or comments?


Ubuntu is an African word that means I can't configure Debian.
8^D
Knoppix, Ubuntu, and several other distributions are all based on
the fine work that the Debian GNU/Linux community does. Debian
GNU/Linux is completely Free, and is developed by volunteers from
around the world.


 I use emacs with rope, ipython and python. I like those in newer versions if
 not bleeding edge.


If you're really serious about having the 'perfect' distro, you can start
with Debian GNU/Linux and make your own, the way you want it to be.
While it is not a trivial matter to re-master a Linux Live CD, it is much
easier than it used to be! You could pack it full of Python! It is this
reason that there are hundreds of Linux Live CD distributions. Each
person thinks that their distro is the best. This is one reason why
GNU/Linux is so fantastic!

 Med venlig hilsen/Kind regards

 Michael B. Arp Sørensen
 Programmer / BOFH
 Denmark

 If you want to enter my network while I'm out, you can find my SSH-key
 under my mouse mat - Michael Bernhard Arp Sørensen


Why don't you make a Python-centric Linux Live CD?
-- 
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


Re: [Tutor] Yet another Python book

2009-04-11 Thread bhaaluu
Thanks for making this book available, Dave!

This stuff looks very useful.

On Fri, Apr 10, 2009 at 8:25 PM, Dave Kuhlman dkuhl...@rexx.com wrote:
 I've collected my training materials plus a few more advanced
 topics and I've also written up a reasonably large set of Python
 exercises.  Then, I turned all of the above into a book.

 If you have comments, suggestions, corrections, etc, I'll
 appreciate them.

 You can get it at no cost, in various formats here:

    http://www.rexx.com/~dkuhlman/#a-python-book

 And, if you really do feel a need to kill a tree, you can purchase a
 copy on paper here:

    http://www.lulu.com/content/paperback-book/a-python-book/2599081

 - Dave


 --
 Dave Kuhlman
 http://www.rexx.com/~dkuhlman
 ___
 Tutor maillist  -  tu...@python.org
 http://mail.python.org/mailman/listinfo/tutor


-- 
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] Fwd: Yet another Python book

2009-04-11 Thread bhaaluu
-- Forwarded message --
From: Tom Green xchime...@gmail.com
Date: Sat, Apr 11, 2009 at 9:38 AM
Subject: Re: [Tutor] Yet another Python book
To: bhaaluu bhaa...@gmail.com


Book looks great.  Any help to master Python is appreciated.

Great work.

Mike.

On Sat, Apr 11, 2009 at 9:04 AM, bhaaluu bhaa...@gmail.com wrote:

 Thanks for making this book available, Dave!

 This stuff looks very useful.

 On Fri, Apr 10, 2009 at 8:25 PM, Dave Kuhlman dkuhl...@rexx.com wrote:
  I've collected my training materials plus a few more advanced
  topics and I've also written up a reasonably large set of Python
  exercises.  Then, I turned all of the above into a book.
 
  If you have comments, suggestions, corrections, etc, I'll
  appreciate them.
 
  You can get it at no cost, in various formats here:
 
     http://www.rexx.com/~dkuhlman/#a-python-book
 
  And, if you really do feel a need to kill a tree, you can purchase a
  copy on paper here:
 
     http://www.lulu.com/content/paperback-book/a-python-book/2599081
 
  - Dave
 
 
  --
  Dave Kuhlman
  http://www.rexx.com/~dkuhlman
  ___
  Tutor maillist  -  tu...@python.org
  http://mail.python.org/mailman/listinfo/tutor
 

 --
 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  -  tu...@python.org
 http://mail.python.org/mailman/listinfo/tutor




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


Re: [Tutor] text editor and debugger for python

2009-03-24 Thread bhaaluu
On Tue, Mar 24, 2009 at 5:08 AM, Bala subramanian
bala.biophys...@gmail.com wrote:
 Friends,

 I do the scripting in Linux. I use vi editor to code. It is not very
 convenient for me. Kindly suggest me a best free text editor ( i can code
 and debug the code simultaneously ) for python based on your experience.

 Thanks
 Bala


Hello Bala,

I use the vim text editor to program in Python. Vim is very similar to vi.
I use the following to make vim easier for programming (save as .vimrc)

 .vimrc

 Created by Jeff Elkner 23 January 2006
 Last modified 2 February 2006

 Turn on syntax highlighting and autoindenting
syntax enable
filetype indent on
 set autoindent width to 4 spaces (see
 http://www.vim.org/tips/tip.php?tip_id=83)
set et
set sw=4
set smarttab
 set line number (added by bhaaluu)
set nu
 Bind f2 key to running the python interpreter on the currently active
 file.  (courtesy of Steve Howell from email dated 1 Feb 2006).
map f2 :w\|!python %cr

After saving the above file as .vimrc (dot vimrc) in your home directory
(/home/bala/.vimrc - for example) you can fire up vim and start
programming in Python.

Press the F2 function key to run your Python code.
When the code completes its run, you are returned to vim for more coding.

For debugging, I use print and raw_input().
I use print to watch variables. I use raw_input() to set breakpoints.

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


Re: [Tutor] help on making python tictactoe

2009-01-19 Thread bhaaluu
On Mon, Jan 19, 2009 at 4:18 AM, jammy007 pp jammy007...@yahoo.com wrote:
 guys , i need immediate help on creating a simple tictactoe game .

 i read micheal dawson's book but didnt quiet get it .

 please help .

 thanks .

 jammy

Python Programming for the Absolute Beginner 2E
by Michael Dawson has the BEST explanation there is
of  programming a Tic-Tac-Toe game! It is explained
in Chapter 6 Functions The Tic-Tac-Toe Game.

If you've read and done the Challenges in Chapters 1-5,
then the 'new' concept on Chapter 6 is how to program
with functions. Otherwise, the Tic-Tac-Toe game is covered
step-by-step.

1. Read Chapter 6.
2. Go back and highlight the important new concepts.
3. Key the Tic-Tac-Toe program into your computer.
   (It is better to key it in than copy/paste it from the CD)
4. Get the game running on your computer. You'll find typos.
   This is part of learning Python. You need to make mistakes.
   Finding and correcting your mistakes is an important part of
   learning how to program a computer..
5. Make a hard-copy print-out of the source code for the game
   you just got running..
6. Play computer by reading and following the program
   flow in the printout. Underline, highlight, and write notes
   in the margins of the printout as you 'play computer'.
7. Do the Challenges for Chapter 6. Challenge No. 4 is to
   plug the hole in the strategy of the game in the book. To do
   that, you'll need to modify the game in the book. If you've
   followed the above instructions, you should have no problems.
8. If you still have problems, post _your_ problem source code to
   this list with an explanation of what your problem is.

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


Re: [Tutor] Coin Flip

2008-10-03 Thread bhaaluu
First off, check your program's indentation.

On Fri, Oct 3, 2008 at 2:04 PM, realNewbie [EMAIL PROTECTED] wrote:

 This is a class assignment, I am to create a program that flips a coin 100
 times and tells me the number of heads and tails.
 I've been working on it for 2 days now and I am stuck. I a trying to run the
 program but it is not running.
 Can someone please point out my error?

 Here is what I have come up with:
 import random
 heads=0
 tails=0
 count=1
 while count 101:
   randomFlip = random.randrange(0,1)
 if randomFlip == 0:
heads = heads + 1
 else:
tails = tails + 1
 count = count + 1
 print heads, heads
 print tails, tails
 --
 View this message in context: 
 http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
 Sent from the Python - tutor mailing list archive at Nabble.com.

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




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


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


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


Re: [Tutor] absolute beginner

2008-09-10 Thread bhaaluu
On Wed, Sep 10, 2008 at 11:29 PM, Johnny [EMAIL PROTECTED] wrote:
 Anyone have any advice for an all out beginner?
 Advice as in... The best book?...best tutor web page?
 I am wanting so badly to learn Python.

 I have went to this site...
 http://www.awaretek.com/tutorials.html

 This gave me lots of info,, but with so many books to choose from, I can't
 seem to find that special one that will give me (a complete dummy) the info
 I need.

 thanks
 Johnny


I found this book to be a great tutorial:

Python Programming for the Absolute Beginner Second Edition.
Michael Dawson.
Boston, MA:Thompson Course Technology, 2006.
ISBN: 1598631128

Dawson uses games to teach Python. The examples are games,
so the book is a lot of fun to work through. Being fun, you'll learn
easier and faster than if the examples were boring academic examples.
Most of the games are text-based, but the last two chapters introduce
you to graphics, sound, music, and animation.

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


Re: [Tutor] hi...

2008-08-24 Thread bhaaluu
On Sun, Aug 24, 2008 at 2:31 AM, Alberto Perez [EMAIL PROTECTED] wrote:
 I have a problem with python, I'm begginner in python. How clear the screen
 of GUI python interactive

I'm not sure what you mean by GUI interactive?
However, at the Python interactive prompt, I can
clear the screen using a simple,  old-fashioned way:

 for i in range(1,50):
 print(\n)

That prints 50 newlines, thus effectively clearing the screen.

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


Re: [Tutor] Online class/education for Python?

2008-07-28 Thread bhaaluu
On Sun, Jul 27, 2008 at 12:13 PM, Dick Moores [EMAIL PROTECTED] wrote:
 At 07:18 AM 7/27/2008, bhaaluu wrote:

 So if
 a student goes through PPftAB2E, and wants to continue programming games,
 I'd recommend Game Programming by Andy Harris [ISBN-13:
 978-0-470-06822-9].
 Game Programming is a fairly complete PyGame tutorial.

 What do you think of _Beginning Game Development with Python and Pygame_,
 Apress, 2007?

 Dick Moores

The main difference between GAME PROGRAMMING and BEGINNING GAME DEVELOPMENT
is that the former deals with 2D scrolling arcade type games, using
PyGame; and the
latter gets into 3D games using PyGame and openGL (I think). I don't
have the McGugan
book, so I don't know for sure. You can take a look at a sample
chapter at Will's site:
http://www.willmcgugan.com/2007/10/04/free-chapter-of-beginning-game-development-with-python-and-pygame/
The publisher also has the source code from the book available.

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


Re: [Tutor] Online class/education for Python?

2008-07-27 Thread bhaaluu
On Sun, Jul 27, 2008 at 3:33 AM, wesley chun [EMAIL PROTECTED] wrote:

 on a tangential note, i may be asked to teach a private course to
 individuals who have never formally learned to program before, and i'm
 participating in this thread for a number of reasons, including the
 fact that i'm trying to come up with a supplemental textbook to use in
 addition to my course notes. i had envisioned the dawson book, but if
 it's going OoP, i will have to come up with alternatives.

 cheers,
 -wesley


While Python wasn't my first computer programming language, I found
the Dawson book (PPftAB2E) to be very approachable, and would highly recommend
it to anyone interested in learning Python. PPftAB2E is just a lot of
FUN to work
through, even if the student isn't planning on becoming a game programmer.
It seems to cover all the Python basics.

I liked the fact that most of the 'games' used as example programs were text-
based games. The introduction to Python OOP was gentle, yet covered most
of the aspects of OOP without being overwhelming. Each chapter in the book
built on the previous chapter's examples.

I learned more about programming, reading/doing PPftAB2E, than from any other
programming book I've read/done. I'd like to repeat that the FUN factor was an
important aspect. Personally, I learn better and faster when I'm
having fun, than
when I have to learn something that is tedious from the very beginning.

Even though PPftAB2E uses games to teach Python, it never really gets
into PyGame.
Instead, it uses a customized version of a PyGame wrapper, called LiveWires.
LiveWires was developed to teach programming to kids in Great Britain. So if
a student goes through PPftAB2E, and wants to continue programming games,
I'd recommend Game Programming by Andy Harris [ISBN-13: 978-0-470-06822-9].
Game Programming is a fairly complete PyGame tutorial.

From the Preface:

quote
Let's face it: Games are fun. Games are what brought me into computer
programming
so long ago, and they're a big part of why I'm still in it. There's
something irresistible
about immersing yourself in an imaginary world. Books and movies are a great way
to experience a form of alternative reality, but an interactive
computer game is
something more. You don't simple watch a game. You 'participate.'

If you think games are fun to play, you should try 'creating' them.
There's nothing
more fun than building your own gaming environment, and when you actually make
something that's exciting for others to play, you'll feel a rare sense
of accomplishment.
If playing games is more immersive than watching movies, writing games is even
more immersive than playing them. After all, the players are really
playing with a
universe constructed by you. In a sense they're playing with you.
/quote

PyGame is a Python wrapper around the extraordinary SDL library, which allows
beginning programmers to do some really incredible things, using the Python
language. The bottom line is: PPftAB2E is a fantastic book to use to
teach people
who have never programmed a computer before; and Game Programming is a
great follow-up book for those from the beginning class who want to continue
learning game programming with Python/PyGame. The PyGame crowd even have
their own website and mailing list: http://www.pygame.org/news.html

There are quite a few Python/PyGame examples on the PyGame website, so an
advanced Python class from the intermediate class would have lots of stuff to
take apart, modify, and put back together. Or, the class could team-build a game
for one of the Python/PyGame game competitions.

So there is a complete curriculum for you. I'm sure that students who
learned how
to program Python by learning to program games, would be well equipped to learn
how to program anything, from networked business apps, to Enterprise apps, or
anything else. They would be well-grounded Problem Solvers who have learned
how to learn. They probably had a lot of FUN learning how to learn, so it sticks
with them better, and longer, I'm so sure. 8^D

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


Re: [Tutor] newbie graphing question

2008-07-27 Thread bhaaluu
On Sun, Jul 27, 2008 at 8:40 AM, Peter Petto [EMAIL PROTECTED] wrote:
 I'm about to try some Python programming for drawing simple geometric
 pictures (for math classes I teach) and was hoping to get some advice that
 will send me off in the best direction.

 I want to write programs that can draw figures with commands akin to
 point(x,y) to draw a point at coordinates (x,y), or segment (x1,y1,x2, y2)
 to draw a segment between points (x1, y1) and (x2, y2)?

 I'd appreciate recommendations as to the best facility or library to use to
 this end. I primarily use a Mac, but my students primarily use Windows.

 I'd love to hear any and all pointers or comments. Thanks!
 --
 ===
 Peter Petto [EMAIL PROTECTED]
 Bay Village, OH   tel: 440.249.4289


Hello Mr. Petto,

I'd recommend the PyGame library. PyGame is a Python wrapper around the
extraordinary SDL library. For an example program of what you might be looking
for, take a look at:

http://www.cs.iupui.edu/~aharris/pygame/ch05/paint.py

The whole site has a lot of Python/PyGame examples:
http://www.cs.iupui.edu/~aharris/pygame/

Andy Harris is a CS professor at Indiana University-Perdue University
Indianapolis,
and is the author of several books, including Game Programming
[ISBN-13: 978-0-470-06822-9], which is a fairly complete introduction
and tutorial
for PyGame.

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


Re: [Tutor] Tutor Newbie

2008-07-25 Thread bhaaluu
On Thu, Jul 24, 2008 at 10:41 PM, Sam Last Name [EMAIL PROTECTED] wrote:
 Hey guys, need some info on programs :)

 Heres a Very simple Script that works with basically any numbers.

 width = input(What is the Width?)
 length = input(What is the Length?)
 area = width*length
 print area
  # my question is what would it take (programs, extra stuff in script,
 ect..) to make this a nice looking usable desktop program?


A usable desktop program probably implies a program that has a
Graphical User Interface (GUI) that can be invoked by clicking on an
Icon that resides on the Desktop. GUI programs might have drop
down menus which in turn might have sub-menus, dialogue boxes,
radio buttons, slider bars, and so forth. The GUI toolkit that usually
ships with Python is Tkinter. Other GUI toolkits that work with Python
include: wxPython, PyQT, PyGTK, PythonCard, AnyGui, and others.

I prefer CLI (Command Line Interface) programs myself, where options
are entered on the command line to do a job. Each program is small and
does one thing very well. Usually the output from one program can be
piped to another program, or input can be piped from another program,
to do the job. The program is usually started from an XTerm, Terminal,
or Konsole, or even from a non-GUI console. These programs usually
are small and fast. Your hands never have to leave the keyboard to
click a mouse button, or whatever.

Anyway, here is a simple Tkinter example from Programming Python 3rd Edition
(which has over 300 pages of Tkinter tutorial in it, plus several
full-feature GUI
programs):

import sys
from Tkinter import *
widget = Button(None, text='Hello widget world', command=sys.exit)
widget.pack( )
widget.mainloop( )

Key in the above code into your favorite text editor, save it as gui2.py,
then run it however you're running Python scripts
I do it like this:
python gui2.py

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


Re: [Tutor] Guidance on jump-starting to learn Python

2008-07-20 Thread bhaaluu
On Fri, Jul 18, 2008 at 1:29 AM, Steve Poe [EMAIL PROTECTED] wrote:

 Any recommended homework assignments?

 I have two books as well:
 Core Python Programming from Wesley Chun , Second Edition.
 Python Programming for the Absolute Beginner, Second Edition.

 Thanks so much for your advice/help in advance.

 Steve

Since you don't have a programming background, the fast track
probably insn't a good idea. The fast track is usually for people
who are already programmers, and want to learn the specifics of
the Python language.

Python Programming for the Absolute Beginner, 2E is an excellent
Python tutorial. If you'll read it from cover to cover, you'll learn Python.
PPftAB2E uses games to teach Python, so it is fun to work through.
Personally, I learn better when something is fun.

Each chapter has exercises at the end. If you can do the exercises,
then you understand the chapter. If you can't do the exercises, then
you probably didn't understand something go back and re-read
that chapter, and try doing the exercises again.

You can always ask questions on this mailing list.

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


Re: [Tutor] Online class/education for Python?

2008-07-20 Thread bhaaluu
Hiyas Steve,

If you're disciplined enough to shell out $$$ for an online class
and do the work, why not just do it on your own? The tuition for
a class will buy you several very nice Python books:

Learning Python. Lutz.
Programming Python. Lutz
Core Python. Wesley Chun.
Python Programming for the Absolute Beginner 2E (if you're new to programming).

Read the book you buy, do the exercises, and if you run into
a problem, ask on this list. You'll end up learning Python, and
have a Python book to refer to as well. The structure of the class
is up to you, depending on what you want to use Python for,
and how the book you choose is written. You take your time,
or do 3-4-5 assignments per week. It's up to you!

If you've never done any programming before, I suggest
Dawson's book (PPftAB2E).

If you've done 'some' programming in another language and
want to learn Python, try Learning Python, followed by Programming
Python, both by Lutz.

If you're an experienced programmer, and want to get up to
speed with Python, try Chun's book. He's also a Tutor on this list.

Otherwise, take a look at all the wonderful free Python books and
tutorials on the Net, and make up your mind to start learning
Python, then DO it. Read some, program some. Ask questions here.

When you ask a question here, try to be as explicit as possible.
Tell the Tutors which platform you're working on (Linux, Mac, MS, other),
which version of Python you're using (ex: 2.4, 2.5, etc.). what you're
trying to do, what the errors are, and if at all possible, show them your
code! This is a beginner's list, so don't be ashamed to show your
beginner code! That is how you will learn! The Tutors won't do your
homework for you, but you'll get plenty of help otherwise!

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!

On Sat, Jul 19, 2008 at 2:41 PM, Steve Poe [EMAIL PROTECTED] wrote:
 Anyone taken or know of any online classes
 teaching Python? I know O'Reilly Press
 teaches online technical courses, through the University of
 Illinois, but no Python
 .

 Thanks.

 Steve

 ___
 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] New to pythong

2008-07-07 Thread bhaaluu
On Mon, Jul 7, 2008 at 12:40 PM, Jeremiah Stack [EMAIL PROTECTED] wrote:


 Hello everybody:

 I am new to this mailing list, and it said that i could the simplest of
 questions. So i was wondering if anyone could be so kind as to e-mail me a
 project idea or something to go out an learn to do in python. I don't know
 any languages, but i am definitely not computer illiterate. i have read so
 many tutorial about getting started but so far that is where the tutorial
 have left me ( how to print  Hello World) and such.

 Any ideas great thanks.


Hi J

Take a look at this stuff:
The book is old, based on ancient line-numbered BASIC.

I started out trying to learn about Text Adventure Games.

So the 'project' is to make the games described in the book
run in Python. There are five games. I got the first three
working, and started on the fourth, then got busy with
other things. However, you can read the book, take apart
the source code I've done, put it back together, modify it,
whatever. It's a fun beginner project, if you're interested
in Text Adventure Games.

http://www.geocities.com/ek.bhaaluu/python/index.html

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
In a world without fences, who needs Gates?
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


Re: [Tutor] Exploring the Standard Library

2008-07-06 Thread bhaaluu
On Sat, Jul 5, 2008 at 2:23 PM, Nathan Farrar [EMAIL PROTECTED] wrote:
 I'd like to spend some time exploring the standard library.  I'm running
 python on Ubuntu.  How would I find the location of the modules (find /
 -name os.py does not yield results)?

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

I'm running a standard Debian 4.0r3 Stable with Python 2.4.4.
I've found the to be helpful. Open a Konsole or Terminal.

[~]$ python

Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type help, copyright, credits or license for more information.

 help('modules')

Please wait a moment while I gather a list of all available modules...

[Modules are spooged here.]

Enter any module name to get more help.  Or, type modules spam to search
for modules whose descriptions contain the word spam.

 help('os')

The help screen for 'os' comes up. Press the spacebar to scroll through it.

 help()

Welcome to Python 2.4!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type quit.

To get a list of available modules, keywords, or topics, type modules,
keywords, or topics.  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as spam, type modules spam.

help quit

 Ctrl-D

[~]$

Another thing that comes in very handy is 'dir(name_of_module)'.
Doing your exploration in the interactive interpreter allows you to read up
on a module, then try it. Have a Konsole with the Python interactive interpreter
and a browser open to the docs at the same time, and really go to town with it!

And so forth, and so on... as you can see, Python itself has an incredible
help engine built-in to the interactive intepreter.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
In a world without fences, who needs Gates?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tic tac toe

2008-07-04 Thread bhaaluu
On Fri, Jul 4, 2008 at 12:14 PM, Akanskha Kumar
[EMAIL PROTECTED] wrote:
 how can i make tic tac toe game using python programing.


There is an excellent tic-tac-toe tutorial in Michael Dawson's book,
Python Programming for the Absolute Beginner Second Edition
(ISBN-13: 978-1-59863-112-8).Chapter 6, pages 159-191.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
In a world without fences, who needs Gates?
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


Re: [Tutor] addressbook program

2008-06-28 Thread bhaaluu
Hello Danny,

Part of learning to program a computer is learning how to solve problems.
I copy/pasted this code directly from the email, and tried to run it, as is.
Error messages in Python are very informative. See below.

On Sat, Jun 28, 2008 at 3:31 AM, Danny Laya [EMAIL PROTECTED] wrote:
 Hi I am making an addressBook program now, and you know some problem, the
 program doesn't work. This is the code :
 
 # Loading the addressbook
 filename = addbook.dat

 def readBook(book)
 import os
 if os.path.exists(filename):
 store = open(filename,'r')
 for line in store:
 name = line.rstrip()
 entry = store.next().rstrip()
 book[name] = entry
 store.close()

The first error I got was:

File xyz.py, line 4
  def readBook(book)
   ^
SyntaxError: invalid syntax

shell returned 1

Press ENTER or type command to continue

The error message pointed me to line 4
and the carot (^) pointed to the end of  def readBook(book)

Can you see the error?
You forgot a colon (:) at the end of the def funcName():

Putting a colon there eliminates that error. One down, more to go


 # Saving the address book
 def saveBook(book):
 store = open(filename,w)
 for name,entry in book.items():
 store.write(name + '\n')
 store.write(entry + '\n')
 store.close()

The next error I get is:

File xyz.py, line 7
  store = open(filename,'r')
  ^
IndentationError: expected an indented block

shell returned 1

Press ENTER or type command to continue

What's the first thing I look at? Which line is the error on?
The error message says it's on line 7. The carot points to
store. The actual message says it is an indentation error.
Fix the indentation.
One more error eliminated...

and so on.. Fix them one at a time, until the program works.
You must have some patience, put in some work, and maybe,
with a little luck, you can learn to program your computer!

Don't give up! Keep trying! You certainly know more than you did
when you started!

What other errors are you getting?


 # Getting User Input
 def getChoice(menu):
 print menu
 choice = int(raw_input(Select a choice(1-4): ))
 return choice

 # Adding an entry
 def addEntry(book):
 name = raw_input(Enter a name: )
 entry = raw_input(Enter a street, town and phone number: )
 book[name] = entry

 # Removing an entry
 def removeEntry(book):
 name = raw_input(Enter a name: )
 del(book[name])

 #Finding an Entry
 def findEntry(book):
 name = raw_input(Enter a name: )
 if name in book:
 print name, book[name]
 else: print Sorry, no entry for: , name

 # Quitting the program
 def main():
 theMenu = '''
 1) Add Entry
 2) Remove Entry
 3) Find Entry
 4) Quit and save
 '''
 theBook = {}
 readBook(theBook)
 choice = getChoice(theMenu)
 while choice != 4:
 if choice == 1:
 addentry(theBook)
 elif choice == 2:
 removeEntry(theBook)
 elif choice == 3:
 findEntry(theBook)
 else: print Invalid choice, try again
 choice = getChoice(theMenu)
 saveBook(theBook)

 # Call the main function
 if __name__ == __main__:
 main()
 
 Help me guy's  Some enlightenment and explanation about the wrong and
 how this program works maybe .. I got this code from Alan Gauld tutorial
 in Handling Files part.


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




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


Re: [Tutor] For Loop question

2008-06-26 Thread bhaaluu
On Thu, Jun 26, 2008 at 9:27 AM, Danny Laya [EMAIL PROTECTED] wrote:
 Hi I'm learning FOR loop now, very easy too learn. But I get confused to
 understand this code :

 myList = [1,2,3,4]
 for index in range(len(myList)):
 myList[index] += 1
 print myList

 And the response is:
 [2, 3, 4, 5]

 Can you explain me as a newbie, how that code works ??
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor


You define a list called myList with 4 integer elements.

 type(myList[0])
type 'int'

You do a for loop on the four elements.

 len(myList)
4

Inside the for loop, you increment each element by one (+= 1).
+= 1 is the same as (variable = variable + 1)

So, just 'play computer' and step through the for loop:
1 + 1 = 2
2 + 1 = 3
3 + 1 = 4
4 + 1 = 5

Thus the output is (2, 3, 4, 5). Still four elements,
each with one added to it.

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


Re: [Tutor] Invoking Python

2008-06-26 Thread bhaaluu
You can create a Python script on a *nix system and run it with:

$ python threeplusfour.py

You can place a shebang line as the first line of the script, which points
to the python interpreter:

#!/usr/bin/python
print(Hello, world!\n)

Save the file, then make it an executable with:

$ chmod u+x threeplusfour.py

Then execute it with:

$ ./threeplusfour.py

Why the dot-slash? Here is a good explanation:
http://www.linfo.org/dot_slash.html

You can also create a Python script and place it in a directory that is
included in your PATH (echo $PATH). Once the executable script is in
a directory in your PATH, you can execute it with:

$ threeplusfour.py

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!

On Thu, Jun 26, 2008 at 9:37 AM, kinuthiA muchanE [EMAIL PROTECTED] wrote:

 On Thu, 2008-06-26 at 12:00 +0200, [EMAIL PROTECTED] wrote:
 Or more commonly add a first line like:

 #! /path/to/python/executable

 Then you can simply make the file executable and run it by typing its
 name

 $ threeplusfour.py

 On my computer, running Linux Ubuntu, I always have to type
 ./threePlusFour.py to get it to run. Otherwise I get a not found
 command.

 or double clicking it in your favourite file manager GUI tool.

 See the topic Add a Little style in my tutorial,  in the box
 Note for Unix users
 for more details.


 ___
 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] Invoking Python

2008-06-26 Thread bhaaluu
On Thu, Jun 26, 2008 at 9:53 AM, Cédric Lucantis [EMAIL PROTECTED] wrote:
 Le Thursday 26 June 2008 15:37:01 kinuthiA muchanE, vous avez écrit :
 On Thu, 2008-06-26 at 12:00 +0200, [EMAIL PROTECTED] wrote:
  Or more commonly add a first line like:
 
  #! /path/to/python/executable
 
  Then you can simply make the file executable and run it by typing its
  name
 
  $ threeplusfour.py

 On my computer, running Linux Ubuntu, I always have to type
 ./threePlusFour.py to get it to run. Otherwise I get a not found
 command.

 This is because on unix the current directory (.) is not in the PATH
 environment variable by default. You can set it if you want but there are
 some security problems with this so it's not recommended. Typing the
 leading './' quickly becomes automatic for unix users.

 --
 Cédric Lucantis
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor


You can make a /home/user/bin directory and add it to your PATH by
including this line in your .bash_profile

# set PATH so it includes user's private bin if it exists
PATH=~/bin:${PATH}

Place your executable Python scripts in ~/bin
Now you can execute them with the dot-slash in front of them
because they are in the PATH. BTW, the tilde (~) is equivalent to
/home/user/.

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


Re: [Tutor] Hands-on beginner's project?

2008-06-25 Thread bhaaluu
Brian Wisti has a very nice tutorial for Python beginners that uses Interactive
Fiction as the basis of a tutorial:

http://coolnamehere.com/geekery/python/ifiction/index.html
http://coolnamehere.com/geekery/python/ifiction/single-round.html
http://coolnamehere.com/geekery/python/ifiction/multiple-scenes.html
http://coolnamehere.com/geekery/python/ifiction/multiple-turns.html

Paul McGuire made an example adventure game using pyparsing:

http://wiki.python.org/moin/PyCon2006/Talks#4
http://www.geocities.com/ptmcg/python/pycon06/adventureEngine.py.txt

(you'll need the pyparsing package for it to work)

http://pyparsing.wikispaces.com/

Python Universe Builder (PUB) is an Interactive Fiction module for
Python. It provides a
programming environment similar to that of Inform or TADS but runs
under any Python
interpreter.

http://py-universe.sourceforge.net/

Here's a link to the Interactive Fiction archive containing a huge
array of text adventure
games and other adventure development tools.

http://www.ifarchive.org/

And finally, another link to TAGs based on Creating Adventure Games On
Your Computer.
http://www.geocities.com/ek.bhaaluu/python/index.html

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!


On Wed, Jun 25, 2008 at 9:39 AM, Jacqui [EMAIL PROTECTED] wrote:
 LOL You rock! That's definitely better than my example. I can't wait to
 get better at this!

 :-D

 On Wed, 2008-06-25 at 09:22 -0400, bob gailer wrote:
 

 Even better is to define a Chapter class, with the various properties
 and methods pertinent thereto, then make each chapter an instance of
 that class.

 class Chapter:

   def __init__(self, desc, ques=None, **actions):
 self.desc = desc
 self.ques = ques
 self.actions = actions
 self.prompt = , .join(actions.keys())

   def describe(self):
 print self.desc

   def ask(self):
 if self.ques:
   print self.ques
   for i in range(10):
 ans = raw_input(self.prompt).lower()
 next = self.actions.get(ans, None)
 if next:
   return next
 else:
   print Invalid response
   else:
 print Too many failed attempts

 def main():
   chapters = [None]*11 # allow for 10 chapters starting with 1
   chapters[1] = Chapter(Ahead of you, you see a chasm., Attempt to
 jump over it?, y=2, n=3)
   chapters[2] = Chapter(Oops - that anvil is heavy. You die.)
   chapters[3] = Chapter(Good choice., Pick a direction, n=4, s=5)
   chapters[4] = Chapter(It's cold in here., Pick a direction, e=1, w=2)
   chapters[5] = Chapter(It's hot in here., Pick a direction, u=6, d=3)
   chapters[6] = Chapter(Congratulations - you found the gold.)
   next = 1
   while True:
 chapter = chapters[next]
 chapter.describe()
 next = chapter.ask()
 if not next:
   print Game over
   break

 main()


 ___
 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] Another Newbie question

2008-06-24 Thread bhaaluu
On Tue, Jun 24, 2008 at 6:23 AM, Danny Laya [EMAIL PROTECTED] wrote:
 Hi I got some problem about writting convention in python. Some tutorial ask
 me to write this :

 a = 1
 s = 0
 print 'Enter Numbers to add to the sum.'
 print 'Enter 0 to quit.'
 while a != 0:
 print 'Current Sum:', s
 a = int(raw_input('Number? '))
 s = s + a
 print 'Total Sum =', s

 And the response must be like this :

 Enter Numbers to add to the sum.
 Enter 0 to quit.
 Current Sum: 0
 Number? 200
 Current Sum: 200
 Number? -15.25
 Current Sum: 184.75
 Number? -151.85
 Current Sum: 32.9
 Number? 10.00
 Current Sum: 42.9
 Number? 0
 Total Sum = 42.9

 But when I write until this :

 a = 1
 s = 0
 print 'Enter Numbers to add the sum'


Try putting the program in a function.
A function is defined using: def functionName():
Everything inside the function is indented.
For example:

def main():
a = 1
s = 0
print 'Enter Numbers to add to the sum.'
print 'Enter 0 to quit.'
while a != 0:
print 'Current Sum:', s
a = int(raw_input('Number? '))
s = s + a
print 'Total Sum =', s

main()

In this example, the function is called main()
and it is defined with with the keyword 'def'
followed by the name of the function, parentheses,
and finally a colon (:). Don't forget the colon!

The body of the function is indented. Make sure you
indent the lines inside the function when you are entering
it in the interactive interpreter. The while loop needs more
indentation with the function body! Look at it carefully!

Finally, call the function. In the above example, the function
is called by entering: main() on a line by itself. It is NOT a
part of the function body.

I hope this is helpful. I remember when I was first starting out
with the Python interactive interpreter. It wasn't easy. Good luck!
Stick with it. It won't be long before you look back on these
beginning days and laugh.

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!

 I press enter, and alas my python response me :
 Enter Numbers to add the sum

 It didn't want waiting me until I finish writing the rest.
 I know there is some mistake about
  my writing convention,
 but what ??? Can you find it ??

 But you know it's not finish,I ignore the error message and
 writng the rest, but until i write this:

 while a != 0:
 ... print 'Current Sum:', s
 ... a = int(raw_input('Number?'))
 ... s = s+a
 ... print 'Total Sum =', s

 Oh, man... another error message :

   File stdin, line 5
 print 'Total Sum =', s
 ^

 Can you help me guys ??










 ___
 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] fibonacci.py task ???

2008-06-24 Thread bhaaluu
On Tue, Jun 24, 2008 at 8:47 AM, Danny Laya [EMAIL PROTECTED] wrote:
 Hi all, can you explain me what this code mean :
 Fibonacci.py

 # This program calculates the Fibonacci sequence
 a = 0
 b = 1
 count = 0
 max_count = 20
 while count  max_count:
 count = count + 1
 # we need to keep track of a since we change it
 old_a = a
 old_b = b
 a = old_b
 b = old_a + old_b
 # Notice that the , at the end of a print statement keeps it
 # from switching to a new line
 print old_a,

 Output:

 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

 Do you understand it
  ??? Can you explain meahhh you know
 i'm a newbie so please explain it with a simple expalanation.

You can start by using Google  or Wikipedia to get basic definitions of
things like Fibonacci sequence. It has to do with mathematics or something?
http://www.google.com
http://www.wikipedia.org/


 And I got many tutorial with title *.py(e.g: Fibonacci.py and Password.py),
 can you explain me what *.py mean? Thank's for helping me.

That is the file extention for a Python Script. The file extension for a BASIC
script is BAS (Fibonacci.bas),  for a Perl script is PL (Fibonacci.pl), for a
Scheme script is SCM (Fibonacci.scm), for a Logo script is LG (Fibonacci.lg)
.

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

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


Re: [Tutor] Hands-on beginner's project?

2008-06-24 Thread bhaaluu
Take a look at this page, and see if it is what you're looking for:

http://www.geocities.com/ek.bhaaluu/python/index.html

I haven't worked on this project in awhile because I got sidetracked
by other things, but it's still on the backburner. One day I'll pick it
up again. I think Text Adventure Games are ripe for learning Python
Object-Oriented Programming (something I'm interested in learning).

Fell free to download the source code and play around with it, modify
it, whatever. It is a beginner's learning project.

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!

On Tue, Jun 24, 2008 at 11:37 AM, nathan virgil [EMAIL PROTECTED] wrote:
 I'm very new to Python, and (to a slightly lesser extent) programming in
 general. I'd like to get some experience by practicing simple-yet-functional
 programs, with a bit of an emphasis on games. The first game I'd like to
 attempt would be a simple, non-linear story, similar to those
 choose-your-adventure books. I don't want to start with anything too
 complicated, like having mapped-out directions, or interactive objects,
 although I do eventually want to get into stuff like that.


 Python seems to me like it would be a good language for this sort of stuff.
 I figure I just need to use a lot of print, if/elif/else, raw_input(), and a
 ton and a half of variables. My problem at the moment is that I don't know
 how to get from one section of the story to the next. I vaguely remember
 reading about some language using a goto command for something like this,
 but I'm not sure how that would be handled in Python.

 A rough idea of what I'm trying to do (in a presumably hypothetical
 language) would be something like this:

 0100  print Ahead of you, you see a chasm.
 0200 jump = raw_input(Do you wish to try jumping over it? Y/N)
 0300 if jump = Y:
 0400   goto 1700
 0500 if jump = N:
 0600  goto 2100

 Does this make any sense? Is there some way I could do this in Python? Any
 and all help is definitely appreciated!

 ___
 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] From Newbie

2008-06-22 Thread bhaaluu
On Sun, Jun 22, 2008 at 6:45 AM, Danny Laya [EMAIL PROTECTED] wrote:
 Hi ! I have learned wiki tutor for non-programmer and I found some hill that
 stopping me. In  Non-Programmer's Tutorial for Python/Count to 10, wiki ask
 me to write this code :

 a = 1
 s = 0
 print 'Enter Numbers to add to the sum.'
 print 'Enter 0 to quit.'
 while a != 0:
 print 'Current Sum:', s
 a = int(raw_input('Number? '))
 s = s + a
 print 'Total Sum =', s


The above code, copy/pasted to a file, and run from the command-line
gives the following output:

Enter Numbers to add to the sum.
Enter 0 to quit.
Current Sum: 0
Number? 1
Current Sum: 1
Number? 2
Current Sum: 3
Number? 3
Current Sum: 6
Number? 4
Current Sum: 10
Number? 0
Total Sum = 10

 But when i write while a != 0: and then i press enter,
 python terminal tell me :
 while a ! = 0:
   File stdin, line 1
 while a ! = 0:
 ^
 SyntaxError: invalid syntax

 Can you
  find my mistake, guys ? Sorry to bother you, I try to
 find the answer in google, but I can't found the answer.
 Please help me soon guys, whatever your answer. If you don't
 want to answer my question, please give me some site that could
 answer this newbie question. Thank's.


The syntax error seems to be the space between the '!' and the '='.
'!=' means 'does not equal'

'! =' doesn't mean anything, thus, the syntax error.

When you're beginning, you'll make plenty of errors like that.
Stop and read the error carefully, then look at the code closely.

As you gain experience, you'll learn to see those nit-picky syntax errors.
It doesn't matter which computer programming language you start out with,
each one has a specific syntax that must be followed, or you'll get syntax
errors. Python is very friendly, and the error messages it gives you are
much more helpful than other languages.

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] Visualizing the Python Project

2008-06-17 Thread bhaaluu
This is very interesting!

http://www.vimeo.com/1093745

Visualizing the commit history of the Python scripting language project.

http://vis.cs.ucdavis.edu/~ogawa/codeswarm/

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


Re: [Tutor] Visualizing the Python Project

2008-06-17 Thread bhaaluu
On Tue, Jun 17, 2008 at 8:26 AM, W W [EMAIL PROTECTED] wrote:
 On Tue, Jun 17, 2008 at 6:40 AM, bhaaluu [EMAIL PROTECTED] wrote:
 This is very interesting!

 http://www.vimeo.com/1093745

 Visualizing the commit history of the Python scripting language project.

 http://vis.cs.ucdavis.edu/~ogawa/codeswarm/

 That would only be cooler if it was written in python ;) (maybe it
 was, but it wasn't specified on the page I read :P)


I know, right?

Michael Ogawa, the UC Davis student who made code_swarm says he
is seriously considering releasing the source code to his project as
open source.
We'll see. He says the source code, as it is now, needs to be cleaned-up
(which indicates it probably wasn't written in Python - since Python, by
its very nature is clean, right?).

Nevertheless, the video of the Python Project is really cool! I like it when
the project explodes in 2000. It's like a SuperNova.
-- 
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


Re: [Tutor] wanting to learn

2008-06-12 Thread bhaaluu
On Thu, Jun 12, 2008 at 3:12 AM, Ken Oliver [EMAIL PROTECTED] wrote:

http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids/

 This sounds interesting to me, but I have not been successful at downloading 
 the text at the link above.  The dreaded 404.  Does anyone have the Windows 
 version of the book or a suggestion as to where to download it?
 ___

Try this link:
http://www.briggs.net.nz/log/wp-content/uploads/2007/09/swfk.zip

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


Re: [Tutor] wanting to learn

2008-06-11 Thread bhaaluu
On Wed, Jun 11, 2008 at 11:16 AM, W W [EMAIL PROTECTED] wrote:

 However, my personal preference is using vi/vim (which you should have
 built in on your mac, along with python).

 If you open a mac terminal window and type vimtutor at the prompt,
 it should start the vim tutor program. There are many programmers
 across various different programming languages and platforms that use
 vi/vim as their ide.

 That's my personal recommendation, and at the very least you should
 give a few different editors/IDEs a try to see which one fits your
 style/comfort zone best.

 HTH,
 Wayne

I also use vim as an IDE for Python.
vim == vi improved.
Here is the (dot)vimrc (.vimrc) I use:

 .vimrc

 Created by Jeff Elkner 23 January 2006
 Last modified 2 February 2006

 Turn on syntax highlighting and autoindenting
syntax enable
filetype indent on
 set autoindent width to 4 spaces (see
 http://www.vim.org/tips/tip.php?tip_id=83)
set et
set sw=4
set smarttab
 set line number (added by bhaaluu)
set nu
 Bind f2 key to running the python interpreter on the currently active
 file.  (courtesy of Steve Howell from email dated 1 Feb 2006).
map f2 :w\|!python %cr

That turns on syntax highlighting, autoindenting, line numbers,
and allows you to press the F2 function key to run your code from vim,
then returns you to the editor afterwards. Use 'print' and 'raw_input()'
to watch variables and establish breakpoints.

vim is touch-typist friendly, so you can really go to town if you know it.
'vimtutor' is a good starting point if you're not familiar with it. You can
do a lot with it, with just a handful of commands. Then add to those
as you need them. Edit multiple files in multiple windows... whatever
you want to do, and more!

There are two modes in vim: normal and insert. Esc will always
get you into normal mode. 8^D

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


Re: [Tutor] wanting to learn

2008-06-11 Thread bhaaluu
On Wed, Jun 11, 2008 at 10:48 AM, Michael yaV [EMAIL PROTECTED] wrote:
 So, can anybody head me in the right direction with my endeavor?

I've read 'Programming Python Third Edition' by Mark Lutz.
O'Reilly  Assoc., 2006. ISBN 0596009259. It has a lot of
stuff about doing things with the Net in it. See if you can find
a copy of it at a used-book store, or someplace like
http://used.addall.com

Just the chapters on using Tkinter (300+ pages) are worth it!

The best Python Tutorial I've found (for me) is:
Python Programming for the Absolute Beginner, Second Edition.
Michael Dawson. ISBN: 1598631128

It is games oriented, but covers all the basics, quite thoroughly.
If you can work through that one, you'll be able to tackle just
about anything Python. Plus, it's a lot of fun to read and do.

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


Re: [Tutor] destroying a window once a movie has stoped playing

2008-05-14 Thread bhaaluu
On Tue, May 13, 2008 at 9:07 PM,  [EMAIL PROTECTED] wrote:


 def movieu(self):
  mov_name = video.mpg
  pygame.mixer.quit()
  screen = pygame.display.set_mode((320, 240))
  video = pygame.movie.Movie(mov_name)
  screen = pygame.display.set_mode(video.get_size())
  video.play()
 while video.get_busy():
  for event in pygame.event.get():
  if event.type == pygame.QUIT:
  break

 this is the peice of code i am using to run a movie in my scissors paper
 rock game so when rock beats scissors a movie will play. i can get the movie
 to play but i would like to no if i can make the window destroy once the
 movie has stoped
  
  This message is intended for the addressee named and may contain privileged
 information or confidential information or both. If you are not the intended
 recipient please delete it and notify the sender.

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


Hey Nick,
You may have better luck asking pygame-specific questions
on the pygame mailing list?

Pygame maintains an active mailing list. You can email the list at
[EMAIL PROTECTED]

To get on or off the mailing list, send an email message to
[EMAIL PROTECTED] with a simple command in the body.
Some examples; (note, no subject is needed). If subscribing or
unsubscribing, there's no need to enter any extra email address
information. Just use the commands like they are below, the email
address you mail from is the address mail will go to (or stop going to).
(from: http://pygame.org/wiki/info)

I think the Tutor list mainly helps with business type scripting
such as accessing a database, opening, writing, reading, closing
files, working with lists, dictionaries, tuples, and so forth? The
pygame list is specific to pygame, and the gurus there can
answer any pygame question you ask them!

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


Re: [Tutor] animations and movies

2008-05-09 Thread bhaaluu
http://pygame.org/news.html

On Thu, May 8, 2008 at 9:40 PM,  [EMAIL PROTECTED] wrote:
 hey just wondering if any one can point me in the right direction for coding
 animations and playing movies
 
 This message is intended for the addressee named and may contain privileged
 information or confidential information or both. If you are not the intended
 recipient please delete it and notify the sender.

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



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


Re: [Tutor] animations and movies

2008-05-09 Thread bhaaluu
On Thu, May 8, 2008 at 9:40 PM,  [EMAIL PROTECTED] wrote:
 hey just wondering if any one can point me in the right direction for coding
 animations and playing movies
 
 This message is intended for the addressee named and may contain privileged
 information or confidential information or both. If you are not the intended
 recipient please delete it and notify the sender.

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



Here's a short pygame example that plays a video.mpg (MPEG 1 file):

#!/usr/bin/python
# movie.py

import sys
import pygame
pygame.init()

mov_name = video.mpg
pygame.mouse.set_visible(False)
pygame.mixer.quit()
screen = pygame.display.set_mode((320, 240))
video = pygame.movie.Movie(mov_name)
screen = pygame.display.set_mode(video.get_size())
video.play()

while video.get_busy():
for event in pygame.event.get():
if event.type == pygame.QUIT:
break


Of course, you'll need a file called video.mpg for the script to work.
-- 
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


Re: [Tutor] animations and movies

2008-05-09 Thread bhaaluu
On Thu, May 8, 2008 at 9:40 PM,  [EMAIL PROTECTED] wrote:
 hey just wondering if any one can point me in the right direction for coding
 animations and playing movies
 
 This message is intended for the addressee named and may contain privileged
 information or confidential information or both. If you are not the intended
 recipient please delete it and notify the sender.

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



Here's an example of a pygame animation:

http://www.cs.iupui.edu/~aharris/pygame/ch08/bounce.py

The site has all sorts of other pygame examples on it.
-- 
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] Python Programming Tools

2008-04-14 Thread bhaaluu
A (mainly Java) programmer on a LUG mailing list asks:

What is a good IDE [for Python] that has Python tools for:

library management,
code completion,
debugging,
documentation,
help

Since I'm not familiar with Java at all, I'm not sure how many
of the things he is asking for, are even relevant for Python?
I'm presuming he is working with a team, and is developing
complex programs.

What do _you use?
-- 
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


Re: [Tutor] input and output files from terminal

2008-04-14 Thread bhaaluu
On Mon, Apr 14, 2008 at 12:55 PM, Brain Stormer [EMAIL PROTECTED] wrote:
 I have a python program which works fine when run using idle but I would
 like call the program from the terminal.

 python test.py -i inputfile -o outputfile

 I tried with raw_input but that only works in idle.  Can this be achieved?
  Thanks

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

Please see:
http://www.faqs.org/docs/diveintopython/kgp_commandline.html

From the book: Dive into Python.
Source code examples from the book:
http://diveintopython.org/download/diveintopython-examples-4.1.zip

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


Re: [Tutor] designing POOP

2008-04-12 Thread bhaaluu
On Sat, Feb 9, 2008 at 9:46 AM, Alan Gauld [EMAIL PROTECTED] wrote:

  As I mentioned in an earlier mail it tends to oscillate in practice.
  You start off looking at the problem to identify the basic classes.
  Then you pick one or two and start designing those in detail and
  that identifies lower level classes. When you reach the point of
  being able to write some code you do so. The act of writing code
  brings up issues that get reflected back up the design - maybe
  even identifying new classes. Once you've written as much
  code as you can you go back up to the problem level, using
  your new found knowledge and design a bit more. Once you
  know enough to start coding go back into code mode again.

  This constant iteration between top level class discovery and low
  level class construction is what Grady Booch refers to in his book
  as Round Trip Gestalt Design and in practice is how most
  software other than the very biggest projects is built.

I recently found the Grady Booch book:
OBJECT ORIENTED DESIGN WITH APPLICATIONS. Benjamin Cummings, 1991.

pg. 189:
As Heinlein suggests, When faced with a problem you do not understand,
do any part of it you do understand, then look at it again. This is just
another way of describing round-trip gestalt design.

pg. 517:
round-trip gestalt design
A style of design that emphasizes the incremental and iterative
development of a system, through the refinement of different yet
consistent logical and physical views of the system as a whole; the
process of object-oriented design is guided by the concepts of
round-trip gestalt design: round-trip gestalt design is a recognition of that
fact that the big picture of a design affects its details, and that the
details often reflect the big picture.

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


Re: [Tutor] Help Writing a Bill Calculating Program

2008-03-28 Thread bhaaluu
On Fri, Mar 28, 2008 at 12:50 AM, Amin Han [EMAIL PROTECTED] wrote:
 Hi, I'm currently a novice at Python, and I need help creating the
  following program...

  # Write a program that asks the user to enter a package number and the
  total number of hours spent online that month (you may assume that the
  user will enter an integer number of hours). Using the information
  below, calculate and print the user's bill for that month.

First of all, carefully read the problem that you have been given.
Most computer programs solve a problem. At a minimum, a program
may ask for INPUT, then do a COMPUTATION of some sort, and finally
OUTPUT an answer or solution. After you've read the problem, get a
pencil and a piece of paper and write down everything you've learned
by reading the problem. At a  minimum, you should write down what
the INPUT is, what needs to be COMPUTED, and what the output is.
Things called variables hold input values, and be used in COMPUTATIONS,
and also used to provide output. It is usually helpful to have meaningful
variable names. At this point, you should have enough information to
write a simple program using pseudocode. Now work through the
pseudocode and desk-check it to see if it will do what you want it to do.
Good. At this point, translating the pseudocode to Python should be
rather straightforward.

  # Modify your program so that it first asks for the total number of
  bills to generate. Your program should use a loop to calculate that
  many customer bills.

In order to modify a program, you need to have a working program.
So, if you don't have a working program yet, go back and work some
more. Once you have a working program, you'll need to review what
you know about loops. Apply that knowledge, using the same steps as
before, to this problem. INPUT-COMPUTATION-OUTPUT

  #If possible, modify your program so that it also calculates and
  prints what the user would have spent if he had one of the other two
  packages. If the user would have saved money using a different
  package, print out an appropriate message (e.g., Package 3 would have
  been cheaper).

Here again, use the same approach as you've already done for this problem.

 *  Package 1: For $9.95 per month, up to 10 hours of access are
  provided. Each additional hour costs $2.00.
 * Package 2: For $13.95 per month, up to 20 hours of access are
  provided. Each additional hour costs $1.00.
 * Package 3: For 19.95 per month, a customer receives an unlimited
  number of hours of access.

The data is very clear. What is package 1? Package 2? Package 3? Read it
and write it down until you understand each one.


  If you could help, that would be much appreciated.  Thanks so much.


I hope this helps you get started. Once you have some Python code written,
and you still have problems, write back and ask for help with your code.
Please include your platform, Python version, and the code you're having
problems with in your post.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor support request.

2008-03-27 Thread bhaaluu
Hello Olrik,

You can post your questions to this list and have access to many
tutors. Generally speaking, if you'll post a code snippet with your
question, it makes replying with a helpful answer much easier.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]

On Thu, Mar 27, 2008 at 6:15 AM, Olrik Lenstra [EMAIL PROTECTED] wrote:
 Hi There:

  I am Olrik. 17 year old student that is practicing IT.
  I recently began learning Python and it's going quite fine.
  I'm following a tutorial at http://www.freenetpages.co.uk/hp/alan.gauld/
  I just finished the branching tab to the left. And i'm about to start
  Modules  Functions.
  However, I've reached a point where I'd like some support from someone
  that is willing to tutor me
  and maybe give me some little assignments that I can practice on.
  I'm really willing to learn how to program Python and generally a fast 
 learner.

  Hope to hear from you soon,
  Regards,
  Olrik
  ___
  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] how to write a function

2008-03-24 Thread bhaaluu
On Mon, Mar 24, 2008 at 8:07 AM, Bartruff, Pamela J.
[EMAIL PROTECTED] wrote:

 Hello Python users,

 I am very new to Python, how do I program that converts 24 hour time to 12
 hour time?  The program should have three functions(input, conversion and
 output function)

 Thanks for any help

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

You define a function with: def functionName():
The body of the function should be indented (4 spaces is good).
So here are examples of 3 'stub' functions that don't do anything (yet):

def input():
# comments go after a hash
# this is the input function
varName = raw_input(Enter input: )
return varName

def conversion(varName):
#  this is the conversion function
# do something here
int(varName)
return varName

def output(varName):
# this is the output function
print (You input %s % varName)

def main():
varName = input()
conversion(varName)
output(varName)

if __name__ == __main__:
main()

You'll have to fill in the parts specific to your problem.
The best way to start is to work the problem out on paper
first: ie. you should already know how to do the math to
convert from 24 hour time, to 12 hour time. If you can't
do it on paper yet, you need to start by learning how to do it
on paper before you can teach the computer how to do it.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Even More Converter!

2008-03-22 Thread bhaaluu
import re
num = 12345678
print ','.join(re.findall(\d{3}, str(num)))

output:
123,456

Where is the '78'?

It looks like that solution inserts comma's from left to right
instead of from right to left.
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]

On Sat, Mar 22, 2008 at 6:17 AM, Kepala Pening [EMAIL PROTECTED] wrote:

  import re

  num = 123456789

  print ','.join(re.findall(\d{3}, str(num)))

  output:
  123,456,789




  - Original Message -
  From: [EMAIL PROTECTED]
  To: tutor@python.org
  Date: Fri, 21 Mar 2008 21:49:18 -0700
  Subject: [Tutor] Even More Converter!

  It works perfectly, so I am sure my question will not be hard to answer.
  When Python gives me the answer to my conversion, is there a way to create it
  so every 3 numbers a comma is inserted?
  Such as: 1 mile is 5,280 feet. Instead of 1 mile is 5280 feet. Yes a simple
  thing, but something which I believe will make it look better.
  Also is there a way to make this so I don't have to go through every
  individual line of code and add *insert comma* or something to it, simply
  at the top like how the Unit Menu is placed only once there, and yet
  applies to the whole document. Thank you
  ___
  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] self-learning Python

2008-03-09 Thread bhaaluu
On Sun, Mar 9, 2008 at 8:54 AM, Kent Johnson [EMAIL PROTECTED] wrote:
   On Sun, Mar 9, 2008 at 8:16 AM, Julia [EMAIL PROTECTED] wrote:
   To be honest I truly dislike the Dawson book. I wouldn't recommend
   it to anyone. It's lacks technical clarity, examples and has a messy
   index. I'm going to sell my example asap.

  I'm not sure what kind of clarity you want. To be sure Dawson is not
  nearly as precise and comprehensive as Learning Python, for example, but
  I think the more casual approach is better for a complete beginner.

  ISTM Dawson is written almost entirely as a series of extended examples,
  I'm really surprised that you say it lacks examples.

I found Dawson's book very approachable for people who are Absolute
Beginners to programming. As Kent says, each chapter is a series of
extended examples that cover fundamental concepts. The premise of
the book is that Game Programming is a FUN way to learn programming.

Most of the book uses text-based games as examples. Each chapter
ends with a set of Challenges that encourage you to test the skills you've
learned up to that point. The Challenges are appropriate for Absolute
Beginners (ie. none of them ask you to do anything that hasn't been
taught yet). Most of the Challenges require a little thought to complete.
Some of the Challenges ask that you modify an example in the chapter
to make it do something different, or to add a new feature.

Chapter 1 starts out with the Game Over Program which is the equivalent
of the Hello, world! program in most other books. This chapter talks you
through getting Python setup and running on your computer, and all sorts
of other essential beginning steps that need to be done in order to use
Python as your programming language.

Chapter 2 uses The Useless Trivia Program to cover Types, Variables, and
simple Input/Output.

Chapter 3 covers Branching (making decisions), 'while' loops, and program
planning. The Guess My Number Game is used as the main example. All
the examples build up to writing the Guessing game.

Chapter 4 has The Word Jumble Game. It covers 'for' loops, Strings, Slicing
Strings, and Tuples.

Chapter 5 introduces Lists and Dictionaries. Here is The Hangman Game.

Chapter 6 covers functions, and The Tic-Tac-Toe Game.

Chapter 7 has The Trivia Challenge Game and covers Files and Exceptions.

Chapter 8 begins the Object Oriented Programming (classes, methods, etc.)
and has The Critter Caretaker Program (a Tamagotchi-type game).

Chapter 9 continues the Object Oriented Programming with The Blackjack
Game. Inheritance, Polymorphism, and other OOP concepts are introduced.

Chapter 10 starts to get into GUI development with Tkinter. The Mad Lib
Program is the main game.

The Final two chapters use a modified version of the LiveWires package to
run the games. You'll need to have PyGame and LiveWires installed for these
games to work.  LiveWires is a wrapper for PyGame which supposedly makes
PyGame easier to lear and use. PyGame is a wrapper for the SDL library,
written in the C programming language.

Chapter 11 gets into Graphics, and the examples build up to The Pizza Panic
Game. Backgrounds, Sprites, Collisions, and other basic graphic gaming
concepts are covered here.

Chapter 12 is a full-blown graphic 2-D arcade-style game called The Astrocrash
Game (similar to 'Asteroids'). Sound, Animation, and Program Development
are covered.

Appendix A is a LiveWires reference.

Games are a really fun way to learn programming, and Dawson's book makes
learning programming a lot of fun! I think the book is meant to be read from
cover to cover, since each chapter is built on the concepts introduced in
previous chapters. Everything is explained clearly without the use of confusing
'jargon'. Terminology is clearly explained, and examples are explained
step-by-step.

If you can finish Dawson's book, you'll be well prepared to take on just about
any other Python tutorial out there (except maybe the ones that delve into
advanced Computer Science theory).


   When I started learning Python, I had had no programming background
   whatsoever. It was Michael Dawson's book that got me off the ground. I
   then read another book Python programming: an introduction to computer
   science, and things began to make sense to me.

  I almost mentioned that one too. Python for Dummies might also be a good
  choice but I haven't seen that.

  O'Reilly is coming out with a book Head First Programming that uses
  Python but it isn't scheduled to be published until May.

  Kent


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


If you finish Dawson's book and are interested in continuing with
Python/PyGame programming (without LiveWires) then you might
want to look into obtaining a copy of Andy Harris' book: Game Programming
published by Wiley (2007). It covers 2-D arcade games with PyGame, and
is a good PyGame tutorial.

Another 

Re: [Tutor] new on the list

2008-02-28 Thread bhaaluu
On Thu, Feb 28, 2008 at 4:51 AM, Alan Gauld [EMAIL PROTECTED] wrote:
  [EMAIL PROTECTED] wrote

   (I wrote these using a simple text editor that I made with Tcl,
   too, http://www.linguasos.org/tcltext.html )

  Fine but it will be easier to use a syntax aware full featured
  editor like vim or Idle or emacs or Scite

  But overall you are on the right lines.


  --
  Alan Gauld
  Author of the Learn to Program web site
  Temorarily at:
  http://uk.geocities.com/[EMAIL PROTECTED]/
  Normally:
  http://www.freenetpages.co.uk/hp/alan.gauld

I also run Python on Linux.  I've tried several of the Python IDEs
(Integrated Development Environments), such as IDLE, Eric, and
so forth, but the best (for me) has been vim. I use the following
.vimrc file:

-8-Cut Here-8---
 .vimrc

 Created by Jeff Elkner 23 January 2006
 Last modified 2 February 2006

 Turn on syntax highlighting and autoindenting
syntax enable
filetype indent on
 set autoindent width to 4 spaces (see
 http://www.vim.org/tips/tip.php?tip_id=83)
set et
set sw=4
set smarttab
 set line number (added by bhaaluu)
set nu
 Bind f2 key to running the python interpreter on the currently active
 file.  (courtesy of Steve Howell from email dated 1 Feb 2006).
map f2 :w\|!python %cr
-8-Cut Here-8---

I run vim in Konsole, but any Xterm works, AFAIK.
Since the Traceback exceptions in Python usually have a line number,
I added that 'feature' to the .vimrc file.
Note the last line that starts with 'map'. That allows you to run your
typed-in Python program from within vim by simply pressing the F2 function key.
At the end of the run, you'll be prompted to press Enter to return to editing
your program in the vim editor.

Since I have vim linked to the 'vi' command, all I have to do to start editing
a new program is to enter a command similar to this at the bash prompt:

$ vi myNewPythonProgram.py

Then, I stay in vim to edit the program, run it, modify it, debug it, etc.
The syntax highlighting and autoindent features enabled in the .vimrc file
make programming in Python a fun and enjoyable experience.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-02-21 Thread bhaaluu
On Wed, Feb 20, 2008 at 6:39 PM, Tiger12506 [EMAIL PROTECTED] wrote:

  I'll throw a couple of thoughts out there since I know that you appreciate
  to see many points of view.


   #!/usr/bin/python

  Hard-coded. That means you have to change the program to change the game. It
  would not be difficult to store this/read it in from a file, making the same
  program suddenly handle an infinite number of games. (well not infinite, but
  at least 19*7*2147483647)


Noted. I'm sure that can be incorporated into a future version.
Also wanted for a future version: SAVE feature, so a game can
be quit in the middle, and not have to be started from scratch
to get back to the same point. HI-SCORES feature shouldn't be
too difficult to implement. etc. etc. etc.

Thanks! 8^D


   # Distribute the treasure
  
   # Place androids/aliens in rooms

  Those two block of code above are SO similar that sure they can be combined
  into one, or at least the first parts of them.


Optimization is the LEAST of my worries at this point.
What these routines DO, and DO 100% of the time
(as far as my tests have shown) is:
1. puts a positive integer into the 6th element of 4 lists in the table
2. puts a negative integer into the 6th element of 4 lists in the table
3. neither routine puts an integer where there is not a zero (no overwriting)
4. neither routine puts an integer in list 6 or list 11

100% of the time!
That's what I was looking for, and these routines do the job.

First: get the routine to do exactly what you want it to do.
Second: Readability. I can read and understand these routines.
Third: Maintainabilty: They are easy to maintain! See Second.

I made a test and ran it 10,000 times in a bash shell script.
I got 100% results. Not 97%, 98%, 99%... but 100%.

If you're interested in my test, ask, and I'll send it.
I used a bash shell script, so I don't know how well the test
will work in MS-Windows:

#!/bin/bash
for i in `seq 1 100` ; do python setupTable.py  setup.out ; done

The new game has 43 rooms, not 19. These routines have already
been ported to the new game, easily and quickly.

No Zen required!

Other beginning programers shouldn't have any problems using
these routines. Plus, I was able to replace the old (97% reliable)
routines with these routines simply by dropping these into place.
They worked immediately, without a hitch, and I'm not greeted
with treasure or a monster at the Entrance or Exit to the game
(6  11 respectively).

100% 8^D
I'll certainly keep your suggestions in mind! Thanks!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-21 Thread bhaaluu
On Wed, Feb 20, 2008 at 7:53 PM, Alan Gauld [EMAIL PROTECTED] wrote:
 Michael Langford [EMAIL PROTECTED] wrote

   I'm firmly with Kent here: OO programming is not about simulation.

  Wooah!
  I'm partly on board here and do agree the noun/verb thing is
  a gross simplification. But it does work and is how probably
  the majority of OOP programmers started out - in the 80's
  and 90's at least. Certainly when I started on OOP around 1984
  it was the de-facto introduction. And it is a still an effective
  way to identify objects if you aren't sure where to start.

  [snipped for brevity]

   Often it feels like the Model objects on real world objects is how
   people are taught so they get the idea of an object. Actually
   designing all code that way is a needless proscription that really
   really hurts many projects.

  I agree with this too. It has to be emphasised that it's only a
  starting point to identify object candidates, the final solution
  may look very different. But in my experience the bigger the
  project the closer the abstractions get to reality at least at
  the object identity level - the operations and data are likely
  to be very different, and underneath that layer will be a wealth
  of lower level abstractions unguessed at by nouns/verbs.

  But heh, if you get presented with a requirements spec
  of 400 pages and over 1000 user storiers (as I just have!) it's
  as good a place to start as any! (IMHO of course! :-)
  And hopefully no newbies on the tutor list is in any danger
  of that happening to them!

  --
  Alan Gauld
  Author of the Learn to Program web site
  http://www.freenetpages.co.uk/hp/alan.gauld
  Which is currently dead awaiting a server repair, sorry! :-(

Somewhere along the line (in the original thread) the idea of
trying to teach a Beginner how to design an OOP in Python
got lost in a bunch of java mumbo jumbo (at least, that's
what it seemed like to me).

After looking at a lot of stuff, and reading much more than
I needed to, the technique that works best for me is the
noun/verb technique. I think it is a good STARTING point!

Now, I understand that there are many different levels of
beginner. Some beginners are higher up the ladder than
others, and they enjoy looking in windows higher up. However,
I'm still on the bottom rung. The technique that I can relate to
is the noun/verb technique. Does this mean that if I get a grasp
of POOP with this technique that I'll be stuck on the bottom
rung forever? I doubt it. No more than someone who is using
whatever technique they are currently using is stuck with that
technique forever.

The universe unfolds perfectly.
Time exists so it doesn't unfold all at once.

I think the noun/verb technique is good for Absolute beginners.
I haven't seen anything else that is so introductory.

Too bad there isn't a graded tutorial that systematically
uses the technique to build several working PYTHON OOPs.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-02-21 Thread bhaaluu
On Thu, Feb 21, 2008 at 7:32 AM, Kent Johnson [EMAIL PROTECTED] wrote:

   Other beginning programers shouldn't have any problems using
   these routines.

  As long as they use the same number of rooms and entrance and exit
  rooms, or they know the places to make the magic edits...

  Kent


Well, no one was able to suggest anything that worked 100% of the time
before. No one.  One routine allots the treasure, The other routine
allots the monsters. Each routine does one thing, and does it well (100%).
It's a text adventure game. It has its own framework.

What? You show me what you're talking about, and I'll run it through my
test script. Your 'clarity' solution should be easily dropped in to replace
the two routines that already work 100% of the time already.
Python please.
The reorganization should be for 'clarity' (a Noob should be able to understand
it, and port it easily to other games that have more or less rooms
[will they have
to make any magic edits anywhere]. Oh, and these clarity routines should be
shorter (in length?).

 Good. However they are longer than necessary.

Did I cover all the things needed? Wait!
No duplications... and something about the random numbers and selection
in the same place? I really don't understand that (yet).

The table is directly related to the map of the game. In the old games, the
monsters and treasures are all in the last column. In the new game, there
are two colums, one for monsters, and the other for treasure. In the treasure
column, numbers 4-18 are distributed randomly to 43 rooms, minus the
entrance, exit, and a 'death' room, and not overwriting numbers 1-3 which
are 'hard-wired' to certain rooms. These numbers reference lists of treasure
names. Likewise, the monster column gets numbers 1-15 distributed
randomly, except for the entrance, exit and 'death' room. These numbers
are also references to list elements.

I wrote the new routines for the new 43-room game. They work 100% of the time.
With minor modifications, they dropped right into the old games. If I make
another new game, with different entrance, exit, or other special rooms,
these routines should drop right in and with minor modifications, just work.
This is the 'framework' for these programs. 8^D

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-02-20 Thread bhaaluu
As far as I can see, these routines give me the results
I'm looking for. I get a distribution of four negative numbers,
four positive integers in the range 10 to 110, and nothing
is placed in room 6 or room 11:

#!/usr/bin/python

import random

#print \n*30

table= [[ 0, 2, 0, 0, 0, 0, 0],# 1
[ 1, 3, 3, 0, 0, 0, 0],# 2
[ 2, 0, 5, 2, 0, 0, 0],# 3
[ 0, 5, 0, 0, 0, 0, 0],# 4
[ 4, 0, 0, 3,15,13, 0],# 5
[ 0, 0, 1, 0, 0, 0, 0],# 6
[ 0, 8, 0, 0, 0, 0, 0],# 7
[ 7,10, 0, 0, 0, 0, 0],# 8
[ 0,19, 0, 0, 0, 8, 0],# 9
[ 8, 0,11, 0, 0, 0, 0],   # 10
[ 0, 0,10, 0, 0, 0, 0],   # 11
[ 0, 0, 0,13, 0, 0, 0],   # 12
[ 0, 0,12, 0, 5, 0, 0],   # 13
[ 0,15,17, 0, 0, 0, 0],   # 14
[14, 0, 0, 0, 0, 5, 0],   # 15
[17, 0,19, 0, 0, 0, 0],   # 16
[18,16, 0,14, 0, 0, 0],   # 17
[ 0,17, 0, 0, 0, 0, 0],   # 18
[ 9, 0, 0,16, 0, 0, 0]]   # 19

# Distribute the treasure
J = 0
while J = 3:
T = int(random.random()*19)+1
if T == 6:
continue
if T == 11:
continue
if T == 13:
continue
if table[T-1][6] != 0:
continue
b = range(10,110)
treasure = random.choice(b)
table[T-1][6] = treasure
J += 1

# Place androids/aliens in rooms
J = 4
while J  0:
T = int(random.random()*19)+1
if T == 6:
continue
if T == 11:
continue
if T == 13:
continue
if table[T-1][6] != 0:
continue
table[T-1][6] = -J
J -= 1

#print dir(table)
for i in range(0,19):
print (%3d % table[i][6]), Rm#,i+1

I simply threw away all the previous attempts that weren't
quite 100% and started over. The final test will be to put
these routines in the old games, and see how they work.
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-12 Thread bhaaluu
On Feb 12, 2008 7:19 AM, Ricardo Aráoz [EMAIL PROTECTED] wrote:

 Did we think about REUSABILITY? What if in some other application I want
 to USE the score, not just display it? What if I want to display it in a
 different form (multiplying it by 100)? Then you are back to our
 original options : either check the score directly, define a getter, or
 a  'stater'(?) which returns the state of the object (in this case
 it would be a tuple with only the score in it, a getter in disguise if
 you ask me). AFAIK the python way is to just check the score, if later
 the object's author changes something he has ways built in in the
 language to keep the interface unchanged (yes, I think the score would
 be part of the interface, otherwise it would be _score).


Everything in this discussion seems relevant to designing Python OOP.
(Python is not java, not javascript, not c++, not visual whatever etc.)
We can see from this that Python does it the Python way. The Java examples
are pretty much wasted on me. (I don't know anything about Java at all.)

The POOP tutorials rarely get into design considerations. They introduce
the mechanics of making a program, make a sample program, and keep
on trucking.  I'm trying to learn how to design a program with Python.

So far, two beginner techniques have been shown: the noun/verb/adjective
method (Alan), and the TDD (Test Driven Design) method (Kent). Of the two,
the noun/verb/adjective method seems more approachable (to me). I think
that once I have some experience doing that, then the TDD method may have
something to offer.

Baby steps first. Walk before running. 8^D
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-11 Thread bhaaluu
On Feb 11, 2008 3:49 AM, Alan Gauld [EMAIL PROTECTED] wrote:

 I think we are in general agreement, albeit with different levels of
 trust/toleration of the technique. Direct access is preferred to
 getter/setter methods but is in turn less desirable that higher
 level methods where they exist. The only contention seems to be
 whether a values() type mutilple-return method is worth anything over
 direct access. My personal taste is that if I need the entire
 official
 state of an object I'd like a method to give it me in one piece, but
 others obviously may feel differently.

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

States, getters-setters, direct access...
I'm still in toilet-training here/ 8^D
Can you provide some simple examples that
illustrate exactly what and why there is any
contention at all?

TIA
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-09 Thread bhaaluu
On Feb 9, 2008 4:09 AM, Alan Gauld [EMAIL PROTECTED] wrote:

 Tiger12506 [EMAIL PROTECTED] wrote

  Are some simple examples off the top of my head. It's not difficult
  to model
  real-life things with classes, but ...

 This is a good point, it is excellent practice for thinking
 about the responsibilities of objects

  ...it is much more difficult to model them
  in such a way that you interact with them normally.

 And this is the bit that does require experience and careful thought.
 But even thinking in the absract about doors, knobs,locks etc helps
 to get the brain attuned to the kind of decions that need to be made

I'm really getting a lot out of this discussion. In my tutorial (PPftAB2E)
the second chapter deals with a Blackjack game. One thing I noticed
(and remember, this is a Noob's viewpoint): The classes seemed to be
designed from small to large, rather than from large to small. First,
a card class was made that had card-object stuff in it (suits and ranks).
Then a hand class was made that inherited the card class. Then, a deck
class was made, that inherited from the hands class (that already had
inherited from the card class). Is this the way you think about designing
classes (small to large). I don't know the proper terminolgy for that yet.

I'm almost ready to start working on another aspect of the adventure game.
I've noticed in my tutorial that several small programs introduce various
classes as the chapter proceeds, then at the end, it is all used to make
the final program. That's fine for the book: no telling how long, or what he
had to do to get it to work that way. But I'm just trying to figure out the
design of the adventure game in small increments. If, in the end, I can
use parts of these small programs to make the final program, great!
But for now, I'm trying to keep it at a manageable size while I'm learning.

There is a castle which has several levels and each level has rooms on it.
The rooms have doors. The doors connect the rooms to each other. Each
room can have either nothing in it, a treasure, or a monster. Each room
has a description which describes 1) Is there a treasure in the room? (and
if so, what is the amount), 2) Is there a monster in it (and if so, what is the
Danger Level), 3) The room description, including where the doors are,
(N,S,E,W,U,D).

I'd like to try and design this small part so that the Explorer can move
around the environment, from room to room, level to level. That's it.
The Explorer will be able to see, but not pick-up treasure (keeping in
mind that treasure can be picked-up in the final game). The Explorer
will be warned about a monster in the room (keeping in mind that the
monster can be fought in the final game).

Design in small chucks. The Castle needs to be setup. Can the Travel
Table from the procedural game be used? Setup requires that the
floorplan, or map of the castle be used to define each room on a level,
all the doors for the rooms, and treasure/terror. One array is used in
the procedural program. Whoops! Sorry. I'm not supposed to think
about it like that!

If I use the small to large approach: A door is the smallest part of a
room. Each room shares doors. Each floor has rooms. All the floors
are in the Castle.

But in this game, all the doors do is connect the rooms. They don't
have knobs or locks. They don't open or close. (Although they MAY
have that ability in some future game?). My thought is you can't
possibly think of all the future things an object can do or be, but
if the class is designed in a very abstract way, then it will be easier
to add a new behavior or characteristic in the future, if needed?
This is what I'm trying to learn with this adventure game exercise.

So, I'm thinking that a door class isn't necessary? The next thing
is a room. A room has doors that connect to other rooms, a
description, and may contain a monster or treasure. This sounds
like a candidate for a class?

The castle has levels. Each level has rooms. Everything happens
in the castle. The equivalent of the castle in the card game would
be the deck of cards. But the deck of cards holds hands (rooms?)
which are shuffled and dealt to people. It does something. What does
the castle DO? It holds rooms, and monsters and treasure is shuffled
and dealt to random rooms (for the Explorer to find).

Not having much experience doing this, makes it harder than it
should be! What is your thought process on this?


  door, or the knob? Does the knob contain a Lock, or does the
  developer only
  need to know that it has one and whether it is locked or not?)

 And its important to remember that the answers will be problem
 dependant.
 There is no absolute right or wrong, just what works best for your
 problem.

 Of course that's why building reusable objects is so hard.
 Something apparently reusable will usually only be reusable
 within a single problem domain. And even then may need to
 be tweaked for the specific problem. It has been estimated
 that 

Re: [Tutor] designing POOP

2008-02-09 Thread bhaaluu
On Feb 9, 2008 8:46 AM, Alan Gauld [EMAIL PROTECTED] wrote:
 bhaaluu [EMAIL PROTECTED] wrote


Some more thoughts on designing here.

You said I can use the procedural program as a program requirement
because it defines I/O. Even though the OOP program will have the
data and functions in classes, I'd like to have the finished program
be identical to the procedural program as far as I/O goes.

So the first little program's I/O looks like this:

WHAT IS YOUR NAME, EXPLORER? _   - first prompt

clrscr()

ZORK, YOUR STRENGTH IS 100
YOU HAVE $  75
IT IS TOO DARK TO SEE ANYTHING

WHAT DO YOU WANT TO DO? _   - second prompt (main game)

So I should be able to 'reuse' some of the code from the first little
program, in the second little program where the castle is setup,
and the player can move around the castle.

IT IS TOO DARK TO SEE ANYTHING is replaced with the room
description, as far as I/O goes, and I'd like for my second little
sample program to follow suit.

When you're designing a program, how do you go about dealing
with text descriptions, like the descriptions for a room? Here is an
example of a room description:

THIS IS THE AUDIENCE CHAMBER
THERE IS A WINDOW TO THE WEST. BY LOOKING TO THE RIGHT
THROUGH IT YOU CAN SEE THE ENTRANCE TO THE CASTLE.
DOORS LEAVE THIS ROOM TO THE NORTH, EAST AND SOUTH.

In the procedural program, it is a function that prints the description:
def room2(): print

The player reads the description, and presses W. There is no west door.
The program's output is:

YOU CANNOT MOVE THROUGH SOLID STONE

and back to the main prompt. Pressing S moves the player through
the South door into another room, where the status of the player is
displayed, and the description of the new room.

The data.py file, with the room descriptions is the biggest file in the
procedural program. I've been told that a data class with a lot of random
data in it is a CodeSmell. Is a data class that has room descriptions in
it, with a function for each room, considered a bad design?

And, since the setup table and the function that decides which room
description is closely related, couldn't they also be a part of that data
class? Is a data class a CodeSmell when all the functions are related?

Or, should I have a room class that can instantiate 19 room objects
which simply accesses the room functions from the data.py file as
it is?

As a side note: Really, the adventure game isn't too much different
from the Bank Account program in your tutorial:: there are several
accounts in the adventure game which are credited and debited
as the game progresses. Pick up treasure: credit my wealth account.
Fight a monster: debit strength account. Move from room to
room: debit strength account. Eat food: credit wealth account.
Buy a weapon: debit wealth account. The real difference between
the two is: moving about the castle and exploring in the adventure
game. In the Bank Account, you are pretty much in one room. You
enter the bank, and leave the bank after taking care of business.

Note: I haven't tried your code snippet below yet, so please keep that
in mind. I may have other thoughts after I try it. These are just some
things I thought about while reading your reply. I don't have any comments
below.
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]

  the second chapter deals with a Blackjack game. One thing I noticed
  (and remember, this is a Noob's viewpoint): The classes seemed to be
  designed from small to large, rather than from large to small.

 As I mentioned in an earlier mail it tends to oscillate in practice.
 You start off looking at the problem to identify the basic classes.
 Then you pick one or two and start designing those in detail and
 that identifies lower level classes. When you reach the point of
 being able to write some code you do so. The act of writing code
 brings up issues that get reflected back up the design - maybe
 even identifying new classes. Once you've written as much
 code as you can you go back up to the problem level, using
 your new found knowledge and design a bit more. Once you
 know enough to start coding go back into code mode again.

 This constant iteration between top level class discovery and low
 level class construction is what Grady Booch refers to in his book
 as Round Trip Gestalt Design and in practice is how most
 software other than the very biggest projects is built.

  I've noticed in my tutorial that several small programs introduce
  various
  classes as the chapter proceeds, then at the end, it is all used to
  make
  the final program. That's fine for the book: no telling how long, or
  what he
  had to do to get it to work that way.

 One of the problems of tutorials (my own included) is that you
 tend

Re: [Tutor] designing POOP

2008-02-08 Thread bhaaluu
On Feb 8, 2008 3:24 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 
 and change the loop from
while True:
 to
while explr.alive:

 This would give you an Explorer class that actually does something useful.

 Kent


It also cleaned up main(), and put everything in well defined packages
at the top of the program. I can see do difference in game play. 8^D
Here are your changes implemented, and working on my Linux system:

#!/user/bin/python

import time

class Explorer(object):
player
def __init__(self,name):
initilaization method
self.name = name
self.strength = 20
self.wealth = 60
self.alive = True

def __str__(self):
return  %s, YOUR STRENGTH IS %d\n YOU HAVE $%d % (self.name,
self.strength, self.wealth)

def change_wealth(self, incr):
self.wealth += incr
if self.wealth = 0:
print
print ( YOU HAVE NO MONEY)
time.sleep(1)

def change_strength(self, incr):
self.strength += incr
if self.strength = 0:
print (\n\n YOU DIED...)
time.sleep(1)
self.alive = False

class Light(object):
light switch

def __init__(self,light):
self.light = light

def __str__(self):
if self.light == 0:
return  IT IS TOO DARK TO SEE ANYTHING
else:
return  THE LIGHTS ARE ON, BUT NO ONE'S HOME

def cs():
print \n*50

def main():
tally = 0
switch = Light(0) #instance
cs() # clear screen
name = raw_input( WHAT IS YOUR NAME, EXPLORER? )
explr = Explorer(name)
while explr.alive:
cs() # clear screen
print explr
print switch
print
print
answer = raw_input( WHAT DO YOU WANT TO DO? [Q|L]: )
if answer.upper() == Q:
break
if answer.upper() == L:
if switch.light == 1:
switch.light = 0
else:
switch.light = 1
explr.change_wealth(-15)
explr.change_strength(-5)
else:
print ( INVALID CHOICE)
tally += 1
print
print ( FINAL SCORE:)
print (TALLY: %d % tally)
print ( STRENGTH: %d % explr.strength)
print (   WEALTH: $%d % explr.wealth)

if __name__ == __main__:
main()

Thanks Kent!
I like these small incremental changes with explanations.
I especially like the way you took blocks of code from main()
and made methods out of them. The actual code itself,
hardly changed!

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-08 Thread bhaaluu
On Feb 7, 2008 9:40 PM, Tiger12506 [EMAIL PROTECTED] wrote:
 There's a couple of errors in here that no one has addressed yet because the
 question was geared towards programming style... So now I will address them.
 Or undress them, I suppose. ;-)

I didn't make much progress until I started thinking
about the Explorer and Light classes as actual objects.

I've tried to address what you undressed. 8^D
Here is another version to undress:

#!/user/bin/python

import time

class Explorer(object):
player
def __init__(self,name):
initilaization method
self.__name = name
self.strength = 20
self.wealth = 60

def get_name(self):
return self.__name

class Light(object):
light switch

def __init__(self,light):
self.light = light

def state(self):
if self.light == 0:
print ( IT IS TOO DARK TO SEE ANYTHING)
else:
print ( THE LIGHTS ARE ON, BUT NO ONE'S HOME)

def cs():
print \n*50

def main():
tally = 0
switch = Light(0) #instance
cs() # clear screen
name = raw_input( WHAT IS YOUR NAME, EXPLORER? )
explr = Explorer(name)
while True:
cs() # clear screen
print ( %s, YOUR STRENGTH IS %d % (explr.get_name(), explr.strength))
print ( YOU HAVE $%d % explr.wealth)
switch.state()
print
print
answer = raw_input( WHAT DO YOU WANT TO DO? [Q|L]: )
if answer.upper() == Q:
break
if answer.upper() == L:
if switch.light == 1:
switch.light = 0
else:
switch.light = 1
explr.strength -= 5
explr.wealth -= 15
if explr.wealth = 0:
print
print ( YOU HAVE NO MONEY)
time.sleep(1)
if explr.strength = 0:
print
print ( YOU DIED...)
time.sleep(1)
break
else:
print ( INVALID CHOICE)
tally += 1
print
print ( FINAL SCORE:)
print (TALLY: %d % tally)
print ( STRENGTH: %d % explr.strength)
print (   WEALTH: $%d % explr.wealth)

if __name__ == __main__:
main()

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-08 Thread bhaaluu
On Feb 8, 2008 4:46 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 bhaaluu wrote:

  It also cleaned up main(), and put everything in well defined packages
  at the top of the program.

 Yes, good OOD puts things into cohesive, comprehensible packages.

  I can see do difference in game play. 8^D

 And that's a good thing, right?

 Refactoring is the process of changing a software system in such a way
 that it does not alter the external behavior of the code yet improves
 its internal structure. -- Martin Fowler in Refactoring

 The refactoring you just did is called Extract Method:
 http://www.refactoring.com/catalog/extractMethod.html

 Kent


This is something that one can only gain from experience?
I really had to struggle to get the Light class to work at all.
I have no idea how many times I started over. But I do feel
that I am starting to learn some of this stuff.

As simple as the adventure game is, I can see that it will
provide lots of practice for me to design and code it in
Python OOP.

Thanks Kent!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-07 Thread bhaaluu
On Feb 6, 2008 8:15 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 
 Design a little, code a little, repeat...
 http://personalpages.tds.net/~kent37/stories/3.html

 
 You can discover many useful design techniques by applying DRY. More here:
 http://personalpages.tds.net/~kent37/stories/00012.html

 
 It has a chapter that explains the code smells and points out
 ways to fix them. An abbreviated version is available here:
 http://wiki.java.net/bin/view/People/SmellsToRefactorings

 The writings of Robert C Martin have taught me a lot about good design
 and agile development.  A lot of his work is available on-line:
 http://objectmentor.com/resources/publishedArticles.html

 http://objectmentor.com/resources/articles/Principles_and_Patterns.pdf
 might be a good starting point.
 http://objectmentor.com/resources/articles/xpepisode.htm attempts to
 give the flavor of agile, test-driven development.

 I don't use the command-line interpreter much, I do a lot more work in
 unit tests.  I have written a little more about this here:
 http://personalpages.tds.net/~kent37/stories/7.html

 HTH,
 Kent

Thank you Kent! I am open to all suggestions as to where to get started
learning how to  design with the Python Object-Oriented Paradigm.
I'm doing a lot of reading, some coding (in my 'testing' directory),
and a lot of thinking about what I'm trying to do. This is a learning situation.
Since I'm a Hobbyist programmer, I don't have a 'class' deadline to meet
(and believe me, I'm happy about that!). I do feel that learning how to do this
will enhance the enjoyment of my Hobby for years to come. I do know that
it will open a lot of doors for me that are currently closed, especially when
it comes to creating games with Python/PyGame, and so forth. Plus, it is
quite possible that this discussion will benefit others who are also just
beginning.

Happy Happy Joy Joy.
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-07 Thread bhaaluu
I was asked:

quote

Here's a situation I often encounter, and I was wondering what the
best practice is.  I've generally initialized my classes' attributes
this same way:

 class TestClass1(object):
  please give me a better name
 def __init__(self):
 please document me
 self.name = 
 self.answer = 
 self.strength = 20
 self.wealth = 45
 self.light = 0
 self.tally = 0

but it could also be done like so:

 class TestClass1(object):
  please give me a better name
 name = 
 answer = 
 strength = 20
 wealth = 45
 light = 0
 tally = 0
 def __init__(self,name=Zed):
 please document me
 self.name = name
 ...etc.

I realize that the two are NOT equivalent if you're using the class as
a static class, rather than instantiating it (e.g. using a static
class called Global while weaning oneself from global variables...)
However, I'm asking about this present case: the class under
discussion will always be instantiated.  It seems to me that declaring
the attributes in the class body makes the class more amenable to
introspection, but are there downsides I'm not seeing?  What's the
best practice?

/quote

I've tried both ways and can't see any difference between
the two as far as input/output is concerned.

Best practice?
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-07 Thread bhaaluu
On Feb 7, 2008 4:58 PM, Eric Brunson [EMAIL PROTECTED] wrote:
 bhaaluu wrote:
  What is the equivalent of JUnit in Python? The article says that JUnit is
  used for unit tests, or you can write your own. Since I don't have a clue,
  writing my own is probably out the question. Also I'm not familiar with
  Java, and am just learning Python OOP, so I'm not getting much out
  of that one. Sorry. Absolute Beginner here.
 

 http://www.google.com/search?q=python+unit+test

 Cleverly called unittest, though sometimes referred to by its original
 project name PyUnit.

 :-)


Cool!
http://docs.python.org/lib/module-unittest.html

The Python unit testing framework, sometimes referred to as ``PyUnit,'' is
a Python language version of JUnit, by Kent Beck and Erich Gamma. JUnit is,
in turn, a Java version of Kent's Smalltalk testing framework. Each is the de
facto standard unit testing framework for its respective language.

Who would have thunk it?
I'll Google and see if I can find a nice PyUnit tutorial.

So, is my first try dong a unit test a total bit-bucket case?
No way to make a test case out of it?
That would be a good example (for me). 8^D
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A bit about python culture

2008-02-07 Thread bhaaluu
On Feb 7, 2008 5:44 AM, Michael Bernhard Arp Sørensen
[EMAIL PROTECTED] wrote:
 Greetings Masters.

 I was wondering if there's a well know word for python programmers, that is
 usable as a domain name. Unfortunately, pug.dk, as in python user group,
 Denmark, is unavailable here in Denmark.

 I hope to acquire a national domain name and let future local user groups
 choose their own third level domain name.

 Any ideas are welcome.

 --
 Kind regards

 Michael B. Arp Sørensen
  Programmer / BOFH

 I am /root and if you see me laughing you better have a backup.
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor


Your best bet might be to look at the old comedy sketches
of Monty Python's Flying Circus. I've found several of their
skits on YouTube. A couple of the more well known sketches
are the Cheese Shop and  the Dead Parrot, but there are
others that may also be a source of ideas for names of a
Python Programming domain.

Even though the logo for many Python Programming sites
is a python snake, the Python Programming language was
named after the British comedy troupe.

Happy Happy Joy Joy.
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-07 Thread bhaaluu
Greetings,

I've read both Kent's and Alan's approaches to designing a POOP,
and am intrigued with the possibilities of the noun/verb/adjective
technique, but am also sympathetic to the TDD method as well
because it is how I've always programmed. I have noted Alan's
comments on the limitations of TDD, as well as the limitations
of the noun/verb/adjective method of design.

The TDD method is the method used in my tutorial:
Python Programming for the Absolute Beginner 2E. Michael Dawson. 2006.
Dawson uses a very simple Tamagotchi example called Critter Caretaker
to introduce the mechanics of POOP. However, perhaps he is using
the TDD method of design?

I'm still experimenting with the noun/verb/adjective design technique,
but I was also itching to get started on something as well, so here is
a first little testing snippet from the testing directory, using the TDD
method. I'm confident that if I am using the terminology incorrectly,
someone will point out the error of my ways. The Tutors are always
saying they really can't help unless they see some code, so this is
a simple adventure game that involves switching a light on and off.
The gameplay isn't all that great, but it is a start. 8^D

#!/user/bin/python

From the testing laboratory of:
b h a a l u u at g m a i l dot c o m
2008-02-07


import time

CS = \n*50

class TestClass1(object):
 please give me a better name
def __init__(self):
please document me
self.name = 
self.answer = 
self.strength = 20
self.wealth = 45
self.light = 0
self.tally = 0

def main():
tc1 = TestClass1() # instance
tc1.__init__() # invoke method
print CS
N1 = tc1.name
N1 = raw_input( WHAT IS YOUR NAME, EXPLORER? )
# main game loop
while True:
print CS
print ( %s, YOUR STRENGTH IS %d) % (N1, tc1.strength)
print ( YOU HAVE $%d) % tc1.wealth
if tc1.light == 0:
print ( IT IS TOO DARK TO SEE ANYTHING)
else:
print ( THE LIGHT'S ON, BUT NO ONE'S HOME)
print
print
A = tc1.answer
A = raw_input( WHAT DO YOU WANT TO DO? [Q|L]: ) # main game prompt
if A.upper() == Q:
break
if A.upper() == L:
light = raw_input( LIGHT? [0|1]: ) # turn the light on and off
if light == 0 and tc1.light == 0:
print ( THE LIGHT IS OFF)
time.sleep(2)
if tc1.wealth = 0:
print
print ( YOU HAVE NO MONEY)
time.sleep(2)
else:
tc1.light = int(light)
tc1.wealth -= 15
else:
print ( INVALID CHOICE)
time.sleep(2)
tc1.tally += 1
tc1.strength -= 5
if tc1.strength = 0:
print ( YOU DIED)
time.sleep(2)
break
print
print ( Final Score:)
print (Tally: %d) % tc1.tally
print (   Wealth: $%d) % tc1.wealth
print ( Strength: %d) % tc1.strength

if __name__ == __main__:
main()


On Feb 7, 2008 4:15 AM, Alan Gauld [EMAIL PROTECTED] wrote:
 Kent Johnson [EMAIL PROTECTED] wrote

  Let me say that I don't mean any disrespect for Alan or his
  approach, I
  just have a different point of view.

 Heh, heh! I was waiting for someone to post a message like this.
 I'll respond by saying the noun/verb thing is not actually the
 method I would normally use (although when all else fails I
 do drop back to it as a starter technique). However I have found
 it to be a techhnique that woerks well for beginners who don't
 know how to get started. Partly because it is fairly mechanistic.

 But noun/verb does have some problems and often produces
 designs that have too many classes and that do not make
 best use of OOP idioms like polymorphism or abstraction.
 But for beginners and in small problems it is a good starter.

  Also I will say that converting a procedural program to OO 'just
  because' is not necessarily a good idea. Not every program is
  improved
  by OOP. In your case, it probably will be though.

 This is absolutely true. Too many people approach OOP as
 if it were some kind of holy grail that is inherently better
 than other styles - it isn't, its just another tool in the toolkit.

  I tend to work from small pieces to larger ones and let the design
  grow
  from the needs of the code, rather than from considerations of nouns
  and
  verbs in the spec.

 I agree at the micro level and in fact my discussion of
 explorers and monsters merging into a figher superclass
 hopefully illustrates how that micro level design/code cycle
 can generate new features of a design including new
 classes/objects. Many OO Design gurus have commented
 on the way that OO design tends to cycle between top down
 design - identifying core classes - and bottom up design - writing
 the lowest building blocks and using that to discover more
 about the higher level needs.

 OO 

Re: [Tutor] designing POOP

2008-02-07 Thread bhaaluu
On Feb 7, 2008 4:07 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 bhaaluu wrote:

  The TDD method is the method used in my tutorial:
  Python Programming for the Absolute Beginner 2E. Michael Dawson. 2006.
  Dawson uses a very simple Tamagotchi example called Critter Caretaker
  to introduce the mechanics of POOP. However, perhaps he is using
  the TDD method of design?

 I don't think Dawson uses TDD. AFAIK he doesn't talk about unit-testing
 at all, which is the fundamental practice of TDD. For an example of unit
 tests in Python, see
 http://docs.python.org/lib/minimal-example.html

  here is
  a first little testing snippet from the testing directory, using the TDD
  method. I'm confident that if I am using the terminology incorrectly,
  someone will point out the error of my ways.

 I think you are using the terminology incorrectly. I would call this an
 example of experimental programming, maybe. A classic example of TDD in
 Java is here:
 http://junit.sourceforge.net/doc/testinfected/testing.htm

What is the equivalent of JUnit in Python? The article says that JUnit is
used for unit tests, or you can write your own. Since I don't have a clue,
writing my own is probably out the question. Also I'm not familiar with
Java, and am just learning Python OOP, so I'm not getting much out
of that one. Sorry. Absolute Beginner here.


  class TestClass1(object):
   please give me a better name
  def __init__(self):
  please document me
  self.name = 
  self.answer = 
  self.strength = 20
  self.wealth = 45
  self.light = 0
  self.tally = 0

 This is a good example of a data class - a class that is just a
 container for data. That is a code smell. It seems to contain unrelated
 values - name and strength are attributes of the player, light is an
 attribute of the environment. So it should probably be more than one
 class, or, since the entire program is in one loop, these could just be
 local variables of main().

Well, most of these were local variables in main() in the procedural
version of this program. So DataClass() is what I should name such
a class. I was wondering about that. These variables were all initialized
in the procedural program before the loop started. Also, the Castle
was setup as part of the initialization, but I'm not dealing with that
here. I'm just trying to learn how to design here. I figured I'd put the
Castle setup in it's own class because it is an object (using the
model as a real-world object method). I don't think I can worry
about whether the CodeSmells at this point. I'm thinking I need
to design something that works, then be able to refactor it to
eliminate as many CodeSmells as I can. But! Noted: a DataClass
is a CodeSmell.


  def main():
  tc1 = TestClass1() # instance
  tc1.__init__() # invoke method

 The __init__() method is called implicitly by calling TestClass1().
 Generally the only time you explicitly call __init__() is when calling
 the method of a base class.

I can fix that right now! Back to the laboratory! 8^D


 Kent


Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-07 Thread bhaaluu
On Feb 7, 2008 6:47 PM, Alan Gauld [EMAIL PROTECTED] wrote:

 Alan Gauld [EMAIL PROTECTED] wrote

  What is the equivalent of JUnit in Python?
 
  I think the nearest equivalent is
 

 Oops, I was going top say PyUnit then remembered the name
 had changed but forgot to check out the latest incarnation.
 Fortyunately others have done the work for me.

 Personally I like the Nose framework that comes with
 TurboGears but even hand written unit tests are no big
 deal in Python - just use asserts and other invariant
 checks and tests etc liberally


 Alan G.

PyUnit:
It really doesn't seem to be an absolute beginner technique.
The noun/verb/adjective technique seems to be geared
more towards beginners. I like the idea of that technique.
Perhaps the unit test approach is more for Intermediate
learners, or learners who already have a background in
OOP of some form or another (like Java). I'm just starting out,
so I'm looking at everything that is thrown at me, but quite
frankly, it is really easy for me to see something that is over
my head at this point. If it's over my head, I'll just stall, like
I have in the past, and then I'll have to start this thread over
again later. sigh 8^D

I guess you can tell it's been a long day for me. I've done
some reading, some coding, some experimenting... all in
a day's play for a Hobbyist Programmer. 8^D

I'll take another look at PyUnit tomorrow morning
when I'm fresh.

One thing I'm encouraged by: in Alan's tutorial, he
says that I don't have to see the light to use POOP.
But if I can learn some basic design POOP techniques
from all this, then I'll be happy. After all, I'm a beginner...
you can't get any more basic than that!

Happy Happy Joy Joy.
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-06 Thread bhaaluu
On Feb 5, 2008 3:02 PM, Alan Gauld [EMAIL PROTECTED] wrote:

 One of the earliest ways of doing this has now fallen sonewhat
 out of favour but in practie I find it works quite well for beginners
 is:

 Describe the problem in plain English text(or whatever you
 language is!). Underline the nouns and separate into proper
 and common nouns. Common nouns are likely classes (although
 be careful to check for synonyms - the same class described
 by different nouns) while proper nouns are likely to be instances
 of classes (which classes may or may not be in your list of
 common nouns) Identify the common noun (class) that applies
 and add to your list.

This sounds like a good suggestion! I've already started, and have a rough
draft. I still need to knock the rough edges off the description. How
detailed do you make your description? Do you write an overview
that isn't very detailed, or do you describe every detail you can
think of? (My rough draft is quite detailed because I have just finished
writing the procedural program, and have all the details in my head.)

Actually, writing a description of the problem in Plain English is part
of designing any computer program (according to some old programming
texts I have). This is why beginning computer programmers should stay
awake in English class, and pay attention to grammar!

 Now go through and identify the verbs and adjectives in the text.
 Assign each to a noun. Verns are potential methods of the classes
 and adjectives are potential attributes.

Noted: potential


 The end result is a candidate set of classes with potential
 methods and attributes. Now try linking them together to identify
 relationships. Don't be surprised if not all classes are related to
 others - you will usuially identify more classes than you need
 and some classes will be demoted to attributes of other more
 significant classes. And a few attributes may get promoted to
 classes in their own right.

I had a 'testing' directory when I wrote the procedural version of the
program. I tested snippets of code to see if they would work, before
putting them in the main program. I can see that a similar 'testing'
directory will be well used when designing this POOP version. 8^D

 Once you have your candidate classes pick a few that look
 like they will be core to the problem and try to work through
 some scenarios focussing on the interactions between the
 objects. At this point its often good to think of the objects
 in physical terms - as if you were building a mechanical
 model of the problem rather than a software version. What
 kinds of signals or messagews would you send to each
 object and how would each object interact with those
 around it

This is why I chose the Text Adventure Game as a learning program.
It is full of objects that can be thought of in physical terms! I'm not
quite clear how they will message each other (yet), but that will
probably become clearer as I work through this.

 Don't at this stage worry too much about inheritance.
 Focus on function. If you find that several classes have
 the same or similar methods then consider if they are
 sub types of an abstract superclass. Do NOT use data
 attributes for this, always base inheritance heirarchies
 on behaviour.

Noted.

 Worth a try. It will miss many OOP tricks but as a starter
 methodology it is how millions of OOP programmers began.
 As you gain experience you will identify common abstract
 patterns. Once that starts then go and read the design
 patterns book by Gamma et al.

This is exactly the kind of thing I was looking for
I'm sure I'll have more questions as I go along.

 Thats how I'd do it, I'm sure others will suggest other
 approaches.

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

Thank you Alan!
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-06 Thread bhaaluu
On Feb 5, 2008 3:02 PM, Alan Gauld [EMAIL PROTECTED] wrote:

 Describe the problem in plain English text(or whatever you
 language is!).
 --
 Alan Gauld
 Author of the Learn to Program web site
 http://www.freenetpages.co.uk/hp/alan.gauld


Here is my description, in plain English.

Text Adventure Game Requirements:
 1. The Explorer enters her name at a prompt.
 2. Other things are initialized at this point.
 3. The layout of the Castle is defined.
 4. Treasure is placed in rooms in the Castle.
A. Treasure is distributed randomly to four rooms.
B. Treasure is placed in two specific rooms.
 5. Four Monsters are randomly distributed to four rooms in the Castle.
A. No monsters should be placed at Entrance or Exit.
B. Each monster has a name.
C. Each monster has a Ferocity Factor / Danger Level.
 6. She has 100 strength and $75 wealth to start with.
A. Strength is decremented 5 for each prompt entry.
   1. If strength equals zero:
  a. She dies.
  b. Final score displayed.
  c. Game over.
B. Strength can be incremented by consuming food.
C. Wealth can be used to buy things in QuarterMaster's Store.
D. Wealth can be incremented by finding and picking-up treasure.
 7. She does not have food, weapons, armor, magic, or light.
 8. She starts at the Entrance to the Castle (Room 6).
 9. She cannot see anything without a light.
10. She enters commands at the prompt in order to:
A. Move in six directions [N,S,E,W,U,D]:
   1. Move in indicated direction.
   2. Informed she cannot move in indicated direction.
   3. Her strength is decremented 5 each move.
   4. The tally of moves is incremented 1 each move.
B. Access the Provisions  Inventory menu [I]:
   1. She must have some wealth to access the PI menu.
   2. She can purchase items from the menu:
  a. Light is 0 or 1.
  b. Weapons: Axe / Sword is 0 or 1.
  c. Food units.
 1. She is told how many units of food she has.
 2. She is asked how many units of food she wants to buy.
  d. Magic amulet.
  e. Armor.
   3. Wealth is decremented after each purchase.
  a. She is informed when she has no money, and exited from the store.
  b. She loses everything except strength and food,
 if she tries to spend more wealth than she has.
C. She can pick-up treasure [P].
   1. She cannot pick-up treasure if she cannot see it (she needs light).
   2. The treasure will remain in the room if not picked-up.
D. She can run from a monster [R].
   1. She may be asked where she wants to flee to (direction).
   2. She may be told she must stand and fight (random decision).
E. She can fight a monster.
   1. Wearing armor increases her chance of success.
   2. If she has a weapon, she must fight with it.
   3. If she has two weapons, she is asked which one she wants to use.
   4. If she has no weapon(s), she must fight bare-handed.
  a. The Explorer or the monster may attack first (random decision).
  b. The Explorer or the monster may wound the other (random decision).
  c. The Explorer or the monster may defeat the other.
 1. Strength is decremented from the Explorer during the fight.
 2. Ferocity Factor is decremented from the monster during
the fight.
11. She can consume food [C].
A. She must have food to consume
   1. She is told how many units of food she has.
   2. She is asked how many units of food she wants to eat.
12. She can use the Magic Amulet [M].
A. She must have the Magic Amulet in her possession.
B. The Magic Amulet will move her to a random room in the Castle.
   1. It should not move her to the Entrance or Exit.
13. The game ends when she exits the Castle (finds Room 11).
A. Exit message is displayed.
B. Final Score is displayed.
   1. Final score depends on several factors:
  a. Strength, wealth, tally, food, number of monsters killed.

Now the hard part: grammar.
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-06 Thread bhaaluu
Thank you Alan.

This helps tremendously! I had gone to your OOP tutorial and read it
over (again) and the closest thing I could find on that page was
the Bank Account example that had a list of things a bank account
might be expected to do. So away I went, making a list.

The problems with that approach surfaced as soon as I started
trying to identify the nouns (potential classes and instances),
adjectives (potential attributes) and verbs (potential methods).

I'm making mistakes, but at least that shows that I'm trying. If nothing
else, I now know what doesn't work. 8^D Actually, I'm not expecting
to get this done today. It may take awhile. From my past experience,
that is how the design process goes. But if I can learn how to do this,
I'm pretty sure it will save a lot of time when I work on future projects.

Back to the drawing board!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]

On Feb 6, 2008 12:06 PM, Alan Gauld [EMAIL PROTECTED] wrote:
 bhaaluu [EMAIL PROTECTED] wrote

  Here is my description, in plain English.
 
  Text Adventure Game Requirements:
  1. The Explorer enters her name at a prompt.
  2. Other things are initialized at this point.
  3. The layout of the Castle is defined.
  4. Treasure is placed in rooms in the Castle.

 Actually thats not really plain English its a very structured
 English. In fact it approaches procedural pseudo code!

 Its possibly a little too detailed too.

 I'd go for a more free-form paragraph or two(at most) something
 like:
 --
 I want to build a text adventure game based around
 an explorer moving around a castle with multiple rooms,. In
 each rooms there could be various items of treasure or monsters.
 To win the game the explorer has to collect as much treasure
 as possible and defeat as many monsters as possible. Treasure
 is worth points and the expolorer starts off with a given amount
 of strength and points. ..

 Because its a text game the interface will consist of a series
 of input prompts with responses and printed status messages.
 The game is over when.
 ---

 That should be shorter and less likely to predispose your thinking
 to a particular approach - such as when the initialisation takes
 place, or how many rooms or premature consideration of the
 command structures etc. These things should emerge as you
 create the object definitions and interactions. The initial aim is
 only to find the half dozen to a dozen key classes top get started.
 Other classes will emerge as you progress, and some of the
 original candidates may merge into others or be discarded.

 And don't forget that there could well be a game class/object to
 control the overall flow of the game and coordinate the actions
 of the other objects. For example the prompt/response/display
 mechanism might be part of the game class (and they might
 be classes too!). This would maximise reuse of the compnent
 objects within a different game framework ( a GUI fort instance)
 later.

 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 maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-06 Thread bhaaluu
On Feb 6, 2008 12:06 PM, Alan Gauld [EMAIL PROTECTED] wrote:
 bhaaluu [EMAIL PROTECTED] wrote

  Here is my description, in plain English.
 
  Text Adventure Game Requirements:
  1. The Explorer enters her name at a prompt.
  2. Other things are initialized at this point.
  3. The layout of the Castle is defined.
  4. Treasure is placed in rooms in the Castle.

 Actually thats not really plain English its a very structured
 English. In fact it approaches procedural pseudo code!

 Its possibly a little too detailed too.

My first try didn't work. I'm going to try again.
I'm intrigued with the idea that the nouns, verbs,
and adjectives can indicate possible classes,
instances, methods, and attributes. While I'm
familiar with the objects in this TAG example,
I'd like to have a way to approach something
that I'm not as familiar with. I like the idea of
this technique. It seems like it should work
with just about anything that can be modelled
as an object.

I have a tendancy to think about
things as actual objects (but probably not OOP
objects -- more like real objects, like a vase).
I also like techniques.

I know this much:

Explorer: has strength  wealth, can carry weapons  food,
can wear armor, can pick-up treasure, can fight monsters,
can wound monsters, can defeat monsters, can move from
room to room.

Monster: can be anywhere, has Ferocity Factor / Danger Level,
can fight Explorer, can wound Explorer, can defeat Explorer.

Treasure: can be picked-up, can be in any room in Castle
(except entrance and exit).

Castle: contains interconnected rooms, has three levels.

Rooms: room has door(s), door(s) connect to other rooms,
room has description, can contain treasure, can contain monster.

The trick is to take all that stuff, and figure out what the classes
are, the instances, the methods, and the attributes. So it seems
I need to write something descriptive about exploring the above.
Subject, verb, adjective object.

I must start somewhere! 8^D
The above is much smaller than my previous pseudocode attempt.


 I'd go for a more free-form paragraph or two(at most) something
 like:
 --
 I want to build a text adventure game based around
 an explorer moving around a castle with multiple rooms,. In
 each rooms there could be various items of treasure or monsters.
 To win the game the explorer has to collect as much treasure
 as possible and defeat as many monsters as possible. Treasure
 is worth points and the expolorer starts off with a given amount
 of strength and points. ..

 Because its a text game the interface will consist of a series
 of input prompts with responses and printed status messages.
 The game is over when.
 ---

 That should be shorter and less likely to predispose your thinking
 to a particular approach - such as when the initialisation takes
 place, or how many rooms or premature consideration of the
 command structures etc. These things should emerge as you
 create the object definitions and interactions. The initial aim is
 only to find the half dozen to a dozen key classes top get started.
 Other classes will emerge as you progress, and some of the
 original candidates may merge into others or be discarded.

 And don't forget that there could well be a game class/object to
 control the overall flow of the game and coordinate the actions
 of the other objects. For example the prompt/response/display
 mechanism might be part of the game class (and they might
 be classes too!). This would maximise reuse of the compnent
 objects within a different game framework ( a GUI fort instance)
 later.

 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


Happy Happy Joy Joy
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] designing POOP

2008-02-05 Thread bhaaluu
Greetings,

POOP: Python Object Oriented Programming/Programmer/Program(s)

I have finished the procedural Python version of the Text Adventure Game.
See attached uuencoded zip file which contains tag10.py, data.py and actions.py.
[uudecode tag.uue; unzip tag.zip; python tag10.zip]

Now I am interested in learning how to DESIGN an object-oriented version
of the game in Python. All my Python tutorials show me the mechanics of
how to MAKE classes. What I'm interested in is the thought processes and/or
guidelines that Tutors employ when they sit down to design a POOP.

Can I use the procedural program as a specification? I'd like the input/output
and gameplay to be the same. However, I'd like to design the program so
it can be expanded in the future. If I'm not mistaken, 'reuse' is a design
criteria?

My main tutorial is:
Programming Python for the Absolute Beginner 2E.
Michael Dawson.
Boston, MA: Thomson Course Technology, 2006.
ISBN-13 978-1-59863-112-8

I also have access to online tutorials. Most of the tutorials I've seen
are mainly about how to MAKE a class, ie. the mechanics of POOP.
Give a person a fish, feed them for a day. Teach them to fish, and
they'll be gone fishing all day. I already have examples of how to
make classes. Can you explain how to DESIGN classes. (I see a
difference here.)

How do you design POOP? What are the guidelines you keep in mind
to design good POOP? Can an absolute beginner learn to design POOP?
8^D
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]


tag.uue
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] designing POOP

2008-02-05 Thread bhaaluu
On Feb 5, 2008 1:13 PM, Marc Tompkins [EMAIL PROTECTED] wrote:

 On Feb 5, 2008 5:46 AM, bhaaluu [EMAIL PROTECTED] wrote:
  What I'm interested in is the thought processes and/or
  guidelines that Tutors employ when they sit down to design a POOP.


 The Code Smells page is as good a starting place as any:
 http://c2.com/xp/CodeSmell.html

 --
 www.fsrtechnologies.com

This page looks good:

http://c2.com/cgi/wiki?PrinciplesOfObjectOrientedDesign

8^D
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] good reference book recommendations

2008-02-04 Thread bhaaluu
Being a book snob, I'd go for the O'Reilly Nutshell book
over the SAMS Essential Reference. I've always had good
luck with books published by O'Reilly. I have neither of
the books you asked about, because I use online docs.
I don't need no steenkin' dead tree Python reference. 8^P
Actually, I've heard several recommendations for the Nutshell
book, but never heard of the Beaszely book. Sprinkle with
salt. Go to Borders or BN and check them out (if they're
on the shelf). It shouldn't take more than a few minutes
for you to see which one fits you!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]

On Feb 4, 2008 6:54 PM, tyler [EMAIL PROTECTED] wrote:
 Hi,

 At the risk of beating a well-dead horse, I'm looking for book
 suggestions. I've already got Core Python Programming, but I find it
 doesn't quite suit my needs. I'd like a comprehensive and *concise*
 reference to the core language and standard libraries. It looks like
 Beazely's Essential Reference and the Martelli's Nutshell book are
 both aimed to fill this role - any reason to choose one over the
 other? The free library reference would almost do for me, except that
 I want a hardcopy and it's a big document to print out.

 Thanks!

 Tyler

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


Re: [Tutor] [Fwd: PyWeek 6 is coming!]

2008-02-02 Thread bhaaluu
Would you consider a python-Tutor team member who:

1. Is new to Python?
2. Never worked with a programming team before?
3. Doesn't have much gaming experience?
4. Doesn't have a recent version of MS-Windows (has Mac OS X or GNU/Linux)?
5. May not be running the latest and greatest version of Python?
6. Is willing to learn!

If so, in what ways could such a team member contribute to the challenge?
(Hoping to start a discussion here!)

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]

On Feb 2, 2008 7:54 AM, Kent Johnson [EMAIL PROTECTED] wrote:
 For all of the budding game authors on the list...maybe there is
 interest in a python-tutor team? (No, I am not volunteering to lead it
 though of course the list is available for help.)

 Kent

  Original Message 
 Subject: PyWeek 6 is coming!
 Date: Fri, 1 Feb 2008 08:11:34 +1100
 From: [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED], [EMAIL PROTECTED],
 [EMAIL PROTECTED]

 PyWeek 6 will run from 00:00 UTC on March 30th through to 00:00 UTC on
 April
 6th.

 Registration is NOT OPEN YET. It will open on Friday 2008/02/29.

 If you're new (or even coming back again) please have a look at the
 rules and
 help pages at http://www.pyweek.org/

 The PyWeek challenge:

 1. Invites entrants to write a game in one week from scratch either
 as an
individual or in a team,
 2. Is intended to be challenging and fun,
 3. Will hopefully increase the public body of game tools, code and
expertise,
 4. Will let a lot of people actually finish a game, and
 5. May inspire new projects (with ready made teams!)

 Entries must be developed in Python during the challenge, and must
 incorporate
 some theme decided at the start of the challenge.


 --
 Visit the PyWeek website:
http://www.pyweek.org/

 ___
 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] Livewires

2008-02-02 Thread bhaaluu
On Feb 1, 2008 11:41 PM, Seon Kang [EMAIL PROTECTED] wrote:
 Python will not recognize the keyboard class of livewires. what is my
 problem? (i have imported the modules and everything)
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

Can you show us the error?
Which platform are you running?
Python/PyGame versions?

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-31 Thread bhaaluu
On Jan 31, 2008 3:19 AM, Alan Gauld [EMAIL PROTECTED] wrote:
 bhaaluu [EMAIL PROTECTED] wrote

  how to program a TAG in Python. My goal is to code
  the game in POOP

 POOP

Python Object Oriented Programming
8^D


  I fixed enough typos in two of the games in the book
  to get them running in a GWBASIC interpreter on an
  old 286 DOS computer.

 Why not run it on a modern computer under QBASIC
 which, last time I looked, was still being shipped with
 Win98 and NT4 - dunno about XP/Vista. But there are
 several unofficial download sites on the web too. And
 the QBASIC IDE is much nicer than GWBASIC

Try it. I'll even send  the code that is working in GWBASIC
to you if you think you can get it working in QBasic. The
286 has all the old interpreters/compilers on it. I used
QBasic to fix most of the typos in the code, but never
could get the code to work in QBasic. (QBasic was the
first interpreter I learned to program with -- I never did
learn the old line-numbered BASIC). Once I fixed everything
I could in QBasic, I fired up the program in GWBASIC and
it runs fine. I don't have MS-XP/Vista/NT. I have MS-DOS 6.2,
MS-Windows 3.1, MS-Windows95. I've been using GNU/Linux
as my primary OS since 1996. My computer museum
includes a 286,386,486, an old Pentium, a 586, and a 686.


 Thats why the original version of my tutorial useed
 QBASIC as one of its languages. It came for free
 with Windows.


I've seen your QBasic/Python tutorial!

 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


Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 29, 2008 9:26 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 Try
  if keY == 6 or keY == 11 or tablE[keY-1][6] != 0:
  tablE[5][6] = 0
  tablE[10][6] = 0

 etc.

 Kent

 PS what's with the strange capitalization of variable names?

It's a test snippet. I use unusual names in my tests.

-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 29, 2008 9:26 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 bhaaluu wrote:
  if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0:
  tablE.values()[5][6] = 0
  tablE.values()[10][6] = 0

 This is not the right way to access the values of a dict. tablE.values()
 is a list of the values in tablE, but it is not in the order you expect;
 it is easiest to think that it is in a random or indeterminate order.

 Try
  if keY == 6 or keY == 11 or tablE[keY-1][6] != 0:
  tablE[5][6] = 0
  tablE[10][6] = 0

 etc.

 Kent


Now that you mention it, I do seem to remember that the order of
a list is indeterminate.

What kind of Python array structure would you use if you need to
access each element in the exact order it appears in the table?
The only element that gets changed is the last one, all the others
stay exactly the same. So far, this structure seems to be working
okay in the big program. Maybe 2-3% of the time is an integer put
in keys 6 or 11.

-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 30, 2008 8:24 AM, Kent Johnson [EMAIL PROTECTED] wrote:
 bhaaluu wrote:
  Now that you mention it, I do seem to remember that the order of
  a list is indeterminate.

 No; the order of a dict is indeterminate, and consequently the order of
 lists derived from dicts with keys(), values(), etc. is indeterminate.

The order of the dictionary is indeterminate. But the key is always
attached to the value, and in my case, the value is a list, so

print tablE.keys() #prints all the keys [in an ordered list, 1-19]

print tablE.keys()[5] #prints the key, 6

print tablE.values() #prints a list of [all [the lists]]

print tablE.values()[5] #prints only the [list for key 6]

print tablE.values()[5][2] #prints the third element: 1

So what you're saying here is that while it might work okay on
my system, that this may not work the same way on another
system?


 The order of a list is determined by how you create it.

Yes, this is how it works in my list test, and this is what my Python
books say. (Although I may have forgotten that on a conscious level,
I am now reminded of it.) 8^D

 
  What kind of Python array structure would you use if you need to
  access each element in the exact order it appears in the table?

 A list of lists may be the correct structure for your program. You could
 define tablE as

 tablE= [[ 0, 2, 0, 0, 0, 0, 0],# 1
  [ 1, 3, 3, 0, 0, 0, 0],# 2
  [ 2, 0, 5, 2, 0, 0, 0],# 3
 ...

 [ 9, 0, 0,16, 0, 0, 0]]   # 19

 Kent


I'll give it a go, and see if I can make that work.
However, except for not getting 100% in my number
distribution routine, the dictionary seems to be working okay
(on my system).

Here's a simple example of the dictionary in action.
for loops have replaced all the if selections... this was the first example.
I've left the if's in so the table.values() can be easily seen.

#!/usr/bin/python
# 2007-01-19
# 2007-01-20

Map
+--+--+
|  |  |
| 5   |
|  1   |  |
|  +--  --+N
|  |  ||
+--  --+  4   | W--+--E
|  |  ||
|  +--  --+S
|  2   |  |
| 3   |
|  |  |
+--+--+

#rm#  N S E W
travelTable = {1:[0,2,5,0],
   2:[1,0,3,0],
   3:[4,0,0,2],
   4:[5,3,0,0],
   5:[0,4,0,1]}

def main():
roomNum = 1
print \

Instructions:
Move through the rooms by pressing [N] for North, [S]
for South, [E] for East, [W] for West, and [Q] to Quit.
These movement keys are not case sensitive (ie. [n] is
the same as [N]).

name = raw_input(What is your name? )
exploring=True
while exploring:
print name + , your strength is,
print str(strength) +.
#
print name,you are in room,roomNum
#
if travelTable.values()[roomNum-1][0] != 0:
print A door leads North.
if travelTable.values()[roomNum-1][1] != 0:
print A door leads South.
if travelTable.values()[roomNum-1][2] != 0:
print A door leads East.
if travelTable.values()[roomNum-1][3] != 0:
print A door leads West.
#
move = raw_input(Which way do you want to go? )
if move.upper() == Q:
exploring=False
#
if move.upper()==N and travelTable.values()[roomNum-1][0] == 0:
print
print You cannot move that way.
if move.upper()==S and travelTable.values()[roomNum-1][1] == 0:
print
print You can't walk through walls.
if move.upper()==E and travelTable.values()[roomNum-1][2] == 0:
print
print Try another direction.
if move.upper()==W and travelTable.values()[roomNum-1][3] == 0:
print
print There is no door to the West.
#
if move.upper() ==N and travelTable.values()[roomNum-1][0] != 0:
roomNum = travelTable.values()[roomNum-1][0]
if move.upper() ==S and travelTable.values()[roomNum-1][1] != 0:
roomNum = travelTable.values()[roomNum-1][1]
if move.upper() ==E and travelTable.values()[roomNum-1][2] != 0:
roomNum = travelTable.values()[roomNum-1][2]
if move.upper() ==W and travelTable.values()[roomNum-1][3] != 0:
roomNum = travelTable.values()[roomNum-1][3]
#
print
main()

-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system

Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 30, 2008 9:22 AM, Kent Johnson [EMAIL PROTECTED] wrote:
 This is implementation dependent.
[snip]

  if travelTable.values()[roomNum-1][0] != 0:

 Again, the use of travelTable.values() is pointless, inefficient (it
 creates a new list every time you call it) and indeterminate. Really,
 you shouldn't be doing this. I can't think of any reason to code this way.

 Kent

This is good to know!
The reason I coded it that way is because I'm learning.
I seem to always be learning... that's why I'm subscribed
to THIS list. 8^D

Back to the drawing board!
Thank you very much for your help!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 30, 2008 3:35 AM, Alan Gauld [EMAIL PROTECTED] wrote:
 In addition to Kents comments about dictionaruy
 access I think there may be another problem in
 your logic.


 bhaaluu [EMAIL PROTECTED] wrote

  The first loop is supposed to populate G with
  a random range of 4 integers 10 to 109
  in random keys 1-19 that have a zero (except keY 6 and  keY 11)
  So keY 6 and keY 11 should both have a zero in G after the
  four integers have been sown.
 
 if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0:
 tablE.values()[5][6] = 0
 tablE.values()[10][6] = 0
 cnt -= 1
 keY = random.choice(a)

 This detects any of the exception cases so a simple else
 clause should be sufficient for the others. However if you
 really want an explicit check...

 if keY != 6 or keY != 11 or table.values()[keY-1][6] == 0:

 This test should use 'and' rather than 'or' since you want
 all of the conditions to be true, not just one of them.
 But since the failing condituions should all have been
 caught above simply using else here would do what
 I think you want.


 b = range(10,110) # 10 to 109
 integer = random.choice(b)
 tablE.values()[keY-1][6] = integer
 cnt += 1


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

Thank you Alan and Kent.
Your suggestions caused me to completely start
from scratch. It also looks like the nested sequence
will be easier to use in the long run (and I'm into this
for the long run!). 8^D

This is working properly now on my
GNU/Linux system running Python 2.4.3:

#!/usr/bin/python
# 2008-01-30

import random

# setup environment
# N S E W U D T
travelTable=[[0,2,0,0,0,0,0],# ROOM 1
 [1,3,3,0,0,0,0],# ROOM 2
 [2,0,5,2,0,0,0],# ROOM 3
 [0,5,0,0,0,0,0],# ROOM 4
 [4,0,0,3,5,13,0],   # ROOM 5
 [0,0,1,0,0,0,0],# ROOM 6
 [0,8,0,0,0,0,0],# ROOM 7
 [7,0,0,0,0,0,0],# ROOM 8
 [0,9,0,0,0,8,0],# ROOM 9
 [8,0,11,0,0,0,0],   # ROOM 10
 [0,0,10,0,0,0,0],   # ROOM 11
 [0,0,0,13,0,0,0],   # ROOM 12
 [0,0,12,0,5,0,0],   # ROOM 13
 [0,15,17,0,0,0,0],  # ROOM 14
 [14,0,0,0,0,5,0],   # ROOM 15
 [17,0,19,0,0,0,0],  # ROOM 16
 [18,16,0,14,0,0,0], # ROOM 17
 [0,17,0,0,0,0,0],   # ROOM 18
 [9,0,0,16,0,0,0]]   # ROOM 19

# distribute positive numbers 10 to 109
# place in last element of 4 random lists
# nothing is placed in list 6 or 11
cnt=0
while cnt = 3:
a = range(1,20)
room = random.choice(a)
if room != 6 and room != 11 and travelTable[room-1][6] == 0:
b = range(10,110)
treasure = random.choice(b)
travelTable[room-1][6] = treasure
else:
cnt -= 1
cnt += 1

# distribute negtive numbers -4 to -1
# place in last element of 4 random lists
# nothing is placed in list 6 or 11
cnt=4
while cnt  0:
a = range(1,20)
room = random.choice(a)
if room != 6 and room != 11 and travelTable[room-1][6] == 0:
travelTable[room-1][6] = -cnt
else:
cnt += 1
cnt -= 1

# put positive numbers in the last element
# of two specific lists overwriting any
# number that exists
a = range(1,99)
travelTable[3][6]= 100 + random.choice(a)
travelTable[15][6]= 100 + random.choice(a)

print  1:, travelTable[0][6]
print  2:, travelTable[1][6]
print  3:, travelTable[2][6]
print  4:, travelTable[3][6]
print  5:, travelTable[4][6]
print  6:, travelTable[5][6]
print  7:, travelTable[6][6]
print  8:, travelTable[7][6]
print  9:, travelTable[8][6]
print 10:, travelTable[9][6]
print 11:, travelTable[10][6]
print 12:, travelTable[11][6]
print 13:, travelTable[12][6]
print 14:, travelTable[13][6]
print 15:, travelTable[14][6]
print 16:, travelTable[15][6]
print 17:, travelTable[16][6]
print 18:, travelTable[17][6]
print 19:, travelTable[18][6]
# end of program

-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 30, 2008 12:46 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 bhaaluu wrote:

  # distribute positive numbers 10 to 109
  # place in last element of 4 random lists
  # nothing is placed in list 6 or 11
  cnt=0
  while cnt = 3:
  a = range(1,20)
  room = random.choice(a)

 room = random.randint(1, 19) is simpler.

  if room != 6 and room != 11 and travelTable[room-1][6] == 0:
  b = range(10,110)
  treasure = random.choice(b)

 Use randint() here too.

  travelTable[room-1][6] = treasure
  else:
  cnt -= 1
  cnt += 1

 This use of cnt is a bit strange. Why not increment only in the
 successful 'if' and get rid of the 'else' entirely?

 Rather than repeating the loop until you get three distinct, valid
 random numbers, you could do something like this:

 # Change 7 rooms, not room 6 or 11
 changeableRooms = range(1, 20)
 changeableRooms.remove(6)
 changeableRooms.remove(11)

 roomsToChange = random.sample(changeableRooms, 7)

 # First three get something good
 for room in roomsToChange[:3]:
travelTable[room-1][6] = random.randint(10, 119)

 # Last four get something bad
 for i, room in enumerate(roomsToChange[3:]):
travelTable[room-1][6] = -i-1

  print  1:, travelTable[0][6]
 etc - use a loop and string formatting:

 for i, room in enumerate(travelTable):
print ' %s: %s' % (i+1, room[6])

 Finally, you might consider putting a dummy entry at travelTable[0], or
 number the rooms from 0, so you don't have to adjust the indices all the
 time.

 Kent


Thank you Kent! All of these look like very useful suggestions.

What I'm trying to do is implement an old Text Adventure Game
that was written c.1983. I'm trying to keep the flavor of the game
as close as possible to the original.

I'm not old enough, in computer years, to remember the Glory Days
of Text Adventure Games on computers like the Apple ][, Atari,
Commodore 64, IBM PC, VIC 20, and so forth. As a result, I don't
know anything about Text Adventure Games. So this is a real
learning experience for me in more ways than just learning Python.

The book I'm using as a reference is at:
http://www.atariarchives.org/adventure/
Creating Adventure Games On Your Computer.
The author was Tim Hartnell.
http://en.wikipedia.org/wiki/Tim_Hartnell

Most of the problems so far stem from the old line-numbered BASIC's
GOTO [line-number] statements. There are other problems as well,
but _that one crops up regularly.

Nevertheless, it has been fun, so far. I'm a Hobbyist programmer, so
even if I don't succeed at making a Retro-game, I'm having fun trying.

At least I'm getting a good idea of what an old-timey Text Adventure
Game is all about. The only thing I can think of of, is that it must have
been quite a challenge to get one of those old computers to do anything
at all so if someone could get a TAG working, it must have been
quite a thrill! 8^D

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 30, 2008 2:24 PM, bob gailer [EMAIL PROTECTED] wrote:
 bhaaluu wrote:
  # N S E W U D T
  travelTable=[[0,2,0,0,0,0,0],# ROOM 1
   [1,3,3,0,0,0,0],# ROOM 2
 It is good to finally see that you are building an adventure game.

 Consider creating a instance of a Room class for each room and saving
 them in a collection such as a list.

 This will give you much more flexibility as your game grows.

WooHoo! YES! This is what I started out wanting to do, as an exercise
in learning Python Object Oriented Programming (POOP). I thought
a Text Adventure Game would be a perfect learning tool because
it seems to have objects that model the real world (or a fantasy world).
There is the Explorer, a world (The Castle), Rooms to explore, objects
in the rooms, like Treasure to be picked-up, and Monsters to fight.

However, not having any experience with Text Adventure Games has
been a real bummer for me as far as designing POOP classes. So I
fell back on procedural programming in order to learn more about
TAGs, so I'd have a better idea about how to design the class in POOP.


 Inevitably I wound up doing a bunch of things more Pythonically so
 there may be stuff here you don't relate to yet. But is is all worth
 studying and will save you hours of headache later.


I really appreciate source code. I probably learn faster by modifying
and running source code than anything else, unless it is a step-by-step
tutorial that also has source code that can be modified and run! 8^D

 - code -
 import random
 class Room:
   roomNo = 0
   def __init__(self, destinations, updatable=True):
 Room.roomNo += 1
 self.roomNo = Room.roomNo
 self.destinations = destinations
 # store treasure apaart from destinations
 self.treasure = 0 # add intial treasure
 self.updatable = updatable # may have the treasure updated
   def updateTreasure(self, treasure):
 self.treasure = treasure
   def __repr__(self):
 return  %s:%s % (self.roomNo, self.treasure)

 rooms = [
   Room([0,2,0,0,0,0]),  # ROOM 1
   Room([1,3,3,0,0,0]),  # ROOM 2
   Room([2,0,5,2,0,0]),  # ROOM 3
   Room([0,5,0,0,0,0]),  # ROOM 4
   Room([4,0,0,3,5,13]), # ROOM 5
   Room([0,0,1,0,0,0], False), # ROOM 6 flagged as not updatable
   Room([0,8,0,0,0,0]), # ROOM 7
   Room([7,0,0,0,0,0]), # ROOM 8
   Room([0,9,0,0,0,8]), # ROOM 9
   # etc for the rest of the rooms -
 ]
   # note I omitted the initial treasure value since it is always 0
   # I modified the last for statement to account for only 9 rooms

 # use random.sample to create random subsets of values and rooms
 # - eliminates all the loops and tests
 # note this ensures no duplicate treasures (do you want that?)

 # create list of 8 random treasure values
 values = random.sample(range(10,110),4) + random.sample(range(-4, 0),4)

 # create list of 8 randomly selected updatable rooms
 roomsToUpdate= random.sample([room for room in rooms if room.updatable], 8)

 # update the rooms' Treasures
 for room, value in zip(roomsToUpdate, values):
   room.updateTreasure(value)

 a = range(1,99)
 for room in (3,5):
   rooms[room].updateTreasure(100 + random.choice(a))

 for room in rooms: print room
 - end code -

I'll copy/paste this into an editor, and see if I can make it do anything.
Thank you!


 Things I did not do, but suggest:
 - store the room destinations in a text file rather than hard-coding
 them in the program. It is almost always a good idea to separate logic
 from data.

Right now, my procedural Python program has a main.py, data.py and
action.py. After Kent told me about using a nested sequence structure
instead of a dictionary, all I had to do was edit data.py and change
the table from a dictionary to a list of lists, then edit the other two
files and do a simple search and destroy to get rid of the  .values() .
It really didn't take as long as I thought it would to change over.


  -create a Treasure class, storing instances directly in roo,s rather
 than indexes, and storing treasure definitions in the text file.

 -store room instances in the destinations rather than indexes.

 At this point you no longer need indexes!

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

Thanks again for the POOP!
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
I got Bob's code running!
Here it is for all nineteen rooms:

#!/usr/bin/python
# 2008-01-30
# bob gailer [Tutor]
import random
class Room:
 roomNo = 0
 def __init__(self, destinations, updatable=True):
   Room.roomNo += 1
   self.roomNo = Room.roomNo
   self.destinations = destinations
   # store treasure apaart from destinations
   self.treasure = 0 # add intial treasure
   self.updatable = updatable # may have the treasure updated
 def updateTreasure(self, treasure):
   self.treasure = treasure
 def __repr__(self):
   return  %s:%s % (self.roomNo, self.treasure)

# Table of Rooms
rooms = [
  Room([0,2,0,0,0,0,0]),# 1 Hallway
  Room([1,3,3,0,0,0,0]),# 2 Audience Chamber
  Room([2,0,5,2,0,0,0]),# 3 Great Hall
  Room([0,5,0,0,0,0,0]),# 4 Private Meeting Room
  Room([4,0,0,3,15,13,0]),  # 5 Inner Hallway
  Room([0,0,1,0,0,0,0],False),  # 6 Entrance (Not Updatable)
  Room([0,8,0,0,0,0,0]),# 7 Kitchen
  Room([7,10,0,0,0,0,0]),   # 8 Store Room
  Room([8,8,8,8,8,8,0]),# 9 Lift
  Room([8,0,11,0,0,0,0]),   #10 Rear Vestibule
  Room([0,0,10,0,0,0,0],False), #11 Exit (Not Updatable)
  Room([0,0,0,13,0,0,0]),   #12 Dungeon
  Room([0,0,12,0,5,0,0]),   #13 Guardroom
  Room([0,15,17,0,0,0,0]),  #14 Master Bedroom
  Room([14,0,0,0,0,5,0]),   #15 Upper Hall
  Room([17,0,19,0,0,0,0]),  #16 Treasury
  Room([18,16,0,14,0,0,0]), #17 Chambermaid's Bedroom
  Room([0,17,0,0,0,0,0]),   #18 Dressing Chamber
  Room([9,0,0,16,0,0,0])]   #19 Small Room

# note I omitted the initial treasure value since it is always 0
# use random.sample to create random subsets of values and rooms
# - eliminates all the loops and tests
# note this ensures no duplicate treasures (do you want that?)

# create list of 8 random treasure values
values = random.sample(range(10,110),4) + random.sample(range(-4, 0),4)
print  values:,values

# create list of 8 randomly selected updatable rooms
roomsToUpdate = random.sample([room for room in rooms if room.updatable], 8)
print 8 rooms:,roomsToUpdate

# update the rooms' Treasures
for room, value in zip(roomsToUpdate, values):
 room.updateTreasure(value)

a = range(1,99)
for room in (3,15):
 rooms[room].updateTreasure(100 + random.choice(a))

for room in rooms:
print room
# end code 


On Jan 30, 2008 2:24 PM, bob gailer [EMAIL PROTECTED] wrote:
 bhaaluu wrote:
  # N S E W U D T
  travelTable=[[0,2,0,0,0,0,0],# ROOM 1
   [1,3,3,0,0,0,0],# ROOM 2
 It is good to finally see that you are building an adventure game.

 Consider creating a instance of a Room class for each room and saving
 them in a collection such as a list.

 This will give you much more flexibility as your game grows.

 Inevitably I wound up doing a bunch of things more Pythonically so
 there may be stuff here you don't relate to yet. But is is all worth
 studying and will save you hours of headache later.

[code snipped - see at top]

 Things I did not do, but suggest:
 - store the room destinations in a text file rather than hard-coding
 them in the program. It is almost always a good idea to separate logic
 from data.

  -create a Treasure class, storing instances directly in roo,s rather
 than indexes, and storing treasure definitions in the text file.

 -store room instances in the destinations rather than indexes.

 At this point you no longer need indexes!

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



Thanks!
Happy Programing!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 30, 2008 10:13 PM, Tiger12506 [EMAIL PROTECTED] wrote:
 If you're looking for examples - I like the zork games...

 http://www.csd.uwo.ca/Infocom/download.html


I've already looked at the Infocom site and didn't find
anything that helped me understand Text Adventure
Games like  Hartnell's book does. BASIC is easy to
read, and with the book's explanations, I'm learning
how to program a TAG in Python. My goal is to code
the game in POOP when I understand enough game
elements to design classes for the various objects in
the game, like rooms, treasure, monsters, and so
forth. Bob Gailer recently sent a POOP example
that does a setup of the environment. His Room class
gave me an idea of how it is done. POOP has been
somewhat difficult for me to grasp. At first, it was all
the new vocabulary. Then connecting the vocabulary
to concepts. Most tutorials revolve around the mechanics
of POOP, but don't really get into how to think about
POOP from a design point of view. I'm pretty sure that
once I get it, I'll wonder why it took me so long... at
least that's how it's been in the past when I've tried to
learn a new concept. So I study it until I hit a block, then
go do something else for awhile. Then I study it some
more. Hartnell's book doesn't get into POOP because
it was written in c.1983 line-numbered BASIC. However,
he has a much better grasp of c.1983 TAGs than I do.
I fixed enough typos in two of the games in the book
to get them running in a GWBASIC interpreter on an
old 286 DOS computer. I can play the game on the 286,
read the code, and read the book. Then I try to do
something similar in Python.

The Infocom games are cool, but they don't give me
the feedback like Hartnell's book and code does.

BTW, there's also RenPy which is an Open Source
Interactive Fiction / Visual Novel engine written in Python.
That's pretty cool, but they aren't at all like the TAGs
in Hartnell's book.

There's also a really nice Adventure game tutorial
over at Brian Wisti's site:
http://coolnamehere.com/geekery/python/ifiction/index.html

References:
http://www.csd.uwo.ca/Infocom/
http://www.atariarchives.org/adventure/
http://en.wikipedia.org/wiki/Tim_Hartnell
http://www.renpy.org/wiki/renpy/Home_Page

Believe me, I've looked at a LOT of stuff trying to get a
handle on Adventure Games. 8^D

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] results not quite 100 percent yet

2008-01-30 Thread bhaaluu
On Jan 30, 2008 11:25 PM, Kent Johnson [EMAIL PROTECTED] wrote:
 bhaaluu wrote:
  References:
  http://www.csd.uwo.ca/Infocom/
  http://www.atariarchives.org/adventure/
  http://en.wikipedia.org/wiki/Tim_Hartnell
  http://www.renpy.org/wiki/renpy/Home_Page
 
  Believe me, I've looked at a LOT of stuff trying to get a
  handle on Adventure Games. 8^D

 I'm surprised you don't have any references to Colossal Cave:
 http://en.wikipedia.org/wiki/Colossal_Cave_Adventure

I've heard of Colossal Cave, but no, I haven't looked at
it (yet?). Most of my searches have tried to be related
to programming an Adventure Game, with less of an
interest in just playing an adventure game. However,
I have tried a couple of the older Infocom games (with
limited success, I might add).


 This article talks about the data files used to define the cave - a good
 example of data-driven programming:
 http://www.digitalhumanities.org/dhq/vol/001/2/09.html

THIS IS SWEET!  This article is really well written.
Actually, Hartnell's book also has a brief history of
adventure games, and Crowther and Woods, among
others are mentioned. Hartnell talks about the
pre-computer gamers who recreated historical battles,
who later went on  and developed Dungeon  Dragons
type games and RPGs (another genre of gaming that
I know nothing about). Later, those games were
computerized.  I'm not sure how many people still
play these games? The local used-book store has
several shelves packed with RPG books.


 Kent


Thanks for these links, Kent!
I never may have found them otherwise.
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul. [Mahatma Gandhi]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] results not quite 100 percent yet

2008-01-29 Thread bhaaluu
Greetings,

I'm having a problem with the following test.
I make a dictionary with 19 keys (1 to 19).
Each key has a list of 7 numbers  (A to G)

# Set up the table
#key#   A  B  C  D  E  F  G
tablE= {1:[ 0, 2, 0, 0, 0, 0, 0],# 1
2:[ 1, 3, 3, 0, 0, 0, 0],# 2
3:[ 2, 0, 5, 2, 0, 0, 0],# 3
4:[ 0, 5, 0, 0, 0, 0, 0],# 4
5:[ 4, 0, 0, 3,15,13, 0],# 5
6:[ 0, 0, 1, 0, 0, 0, 0],# 6
7:[ 0, 8, 0, 0, 0, 0, 0],# 7
8:[ 7,10, 0, 0, 0, 0, 0],# 8
9:[ 0,19, 0, 0, 0, 8, 0],# 9
   10:[ 8, 0,11, 0, 0, 0, 0],   # 10
   11:[ 0, 0,10, 0, 0, 0, 0],   # 11
   12:[ 0, 0, 0,13, 0, 0, 0],   # 12
   13:[ 0, 0,12, 0, 5, 0, 0],   # 13
   14:[ 0,15,17, 0, 0, 0, 0],   # 14
   15:[14, 0, 0, 0, 0, 5, 0],   # 15
   16:[17, 0,19, 0, 0, 0, 0],   # 16
   17:[18,16, 0,14, 0, 0, 0],   # 17
   18:[ 0,17, 0, 0, 0, 0, 0],   # 18
   19:[ 9, 0, 0,16, 0, 0, 0]}   # 19
#key#   A  B  C  D  E  F  G


The first loop is supposed to populate G with
a random range of 4 integers 10 to 109
in random keys 1-19 that have a zero (except keY 6 and  keY 11)
So keY 6 and keY 11 should both have a zero in G after the
four integers have been sown.

# populate G column with range of 4 integers 10 to 109
# in random keys that have a zero [except keYs 6 and 11]
print %*69
cnt=0
while cnt = 3:
print CNT111=,cnt  #debug-remove when done
a = range(1,20) # 1 to 19
keY = random.choice(a)
if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0:
tablE.values()[5][6] = 0
tablE.values()[10][6] = 0
cnt -= 1
keY = random.choice(a)
if keY != 6 or keY != 11 or table.values()[keY-1][6] == 0:
b = range(10,110) # 10 to 109
integer = random.choice(b)
tablE.values()[keY-1][6] = integer
cnt += 1


The second loop is supposed to populate G with
numbers -4 to -1 in random keys 1-19 that have a zero
(except keY 6 and keY11). So once again, 6 and 11 should have
a zero in G after the loop is finished.

# populate G with range of integers -1 to -4
# in random keYs that have a zero [except keYs 6 and 11]
cnt=4
while cnt  0:
print CNT222=,cnt
a = range(1,20)
if keY != 6 or keY != 11 and tablE.values()[keY-1][6] == 0:
keY = random.choice(a)
tablE.values()[keY-1][6] = -cnt
cnt -= 1
if keY == 6 or keY == 11:
tablE.values()[5][6] = 0
tablE.values()[10][6] = 0
cnt += 1


The last thing is that two integers are placed in specific keys
4 and 16, overwriting anything that may be in G whether a
negative number or a number  9.

# Put an integer in G at two specific keys: 4  16
# These will overwrite anything placed there previously
#a = range(1,99)
#tablE.values()[3][6]= 100 + random.choice(a)
#tablE.values()[15][6]= 100 + random.choice(a)

The above has been commented out so I see if the two loops are
each distributing four numbers each, without putting anything
in G of keys 6 and 11.

I've approached the problem by trying to get the loop to repeat
if a number ends up in G at key 6 or key 11. I've done this changing
the loop count. This seems to work about 97% of the time, or so.
I'm looking for 100%.

I know I can always just set those keys to zero before the table is
written, but I'd rather have the table as fully populated by the two
loops and just not have anything get in G in keys 6  11.

Anyway, this is just a short test, part of a larger program.
Here's the test code:

#!/usr/bin/python

import random

print \n*30

# Set up the table
#key#   A  B  C  D  E  F  G
tablE= {1:[ 0, 2, 0, 0, 0, 0, 0],# 1
2:[ 1, 3, 3, 0, 0, 0, 0],# 2
3:[ 2, 0, 5, 2, 0, 0, 0],# 3
4:[ 0, 5, 0, 0, 0, 0, 0],# 4
5:[ 4, 0, 0, 3,15,13, 0],# 5
6:[ 0, 0, 1, 0, 0, 0, 0],# 6
7:[ 0, 8, 0, 0, 0, 0, 0],# 7
8:[ 7,10, 0, 0, 0, 0, 0],# 8
9:[ 0,19, 0, 0, 0, 8, 0],# 9
   10:[ 8, 0,11, 0, 0, 0, 0],   # 10
   11:[ 0, 0,10, 0, 0, 0, 0],   # 11
   12:[ 0, 0, 0,13, 0, 0, 0],   # 12
   13:[ 0, 0,12, 0, 5, 0, 0],   # 13
   14:[ 0,15,17, 0, 0, 0, 0],   # 14
   15:[14, 0, 0, 0, 0, 5, 0],   # 15
   16:[17, 0,19, 0, 0, 0, 0],   # 16
   17:[18,16, 0,14, 0, 0, 0],   # 17
   18:[ 0,17, 0, 0, 0, 0, 0],   # 18
   19:[ 9, 0, 0,16, 0, 0, 0]}   # 19
#key#   A  B  C  D  E  F  G

# populate G column with range of 4 integers 10 to 109
# in random keys that have a zero [except keYs 6 and 11]
print %*69
cnt=0
while cnt = 3:
print CNT111=,cnt
a = range(1,20) # 1 to 19
keY = random.choice(a)
if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0:
tablE.values()[5][6] = 0
tablE.values()[10][6] = 0
cnt -= 1
keY = random.choice(a)
if keY != 6 or keY != 11 or table.values()[keY-1][6] == 0:
b = range(10,110) # 10 to 109
integer = random.choice(b)

Re: [Tutor] Read protection of python files for Abaqus

2008-01-14 Thread bhaaluu
Greetings,
On Jan 14, 2008 3:17 AM, Ferruh KAYHAN [EMAIL PROTECTED] wrote:
 Dear Sirs;
 Good morning.
 I do not like abaqus users will read my python file codes.  How can I
 protect my codes from reading ans still workable by Abaqus import??

 Best Regards
 Ferruh Kayhan

quote source=wikipedia?ABAQUS
Abaqus is widely used in the automotive, aerospace, and industrial
products industries. The package is very popular with academic and
research institutions
...
These software products, especially Abaqus/CAE, extensively use the
open-source scripting language Python for scripting and customization.
/quote

Don't academics and researchers thrive on sharing information?
Also, this forum is geared towards learning Python, and sharing
source code is encouraged in order to obtain help.

Also, many eyes can find and fix bugs in your scripts,
as well as, others may find the scripts useful: ie. research
can advance more quickly.

Is there a particular reason why you don't want others to see your
Abaqus Python scripts?

Just curious.
-- 
b h a a l u u at g m a i l dot c o m
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Review and criticism of python project

2008-01-03 Thread bhaaluu
If you have a web page, you can upload the code to your web page,
then post here with a link to the code and a request for reviews.
That's one way to do it.
-- 
b h a a l u u at g m a i l dot c o m

On Jan 3, 2008 5:00 PM, GTXY20 [EMAIL PROTECTED] wrote:

 Hello all,

 Is there a forum or group where I can upload my python project for review?

 I am new at Python and at this point my program is doing what it needs to I
 just can't help but feeling I have some errors or improper coding going on
 inside.

 Any advice is very much appreciated.

 Thanks.

 GTXY20

 ___
 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] constants, flags or whatever

2007-12-19 Thread bhaaluu
This isn't elegant, but it is a start. My method is: get SOMETHING working,
then work from there. 8^D


constant: moving = m
constant: inserting = i
constant: jumping = j
.
.
action = moving
.
.
.
if action == jumping:
jumpSomewhere()
elseif action == moving:
moveSomewhere()
elseif action == inserting:
insertSomething()

##
moving = False
inserting = False
jumping = False

def jumpingSomewhere():
global jumping
print jumping
jumping = True
return jumping

def insertingSomething():
global inserting
print inserting
inserting = True
return inserting

def movingSomewhere():
global moving
print moving
moving = True
return moving

jumpingSomewhere()
insertingSomething()
movingSomewhere()

print jumping
print inserting
print moving
#

Output:
False
False
False
True
True
True


On Dec 19, 2007 8:44 PM, Jim Morcombe [EMAIL PROTECTED] wrote:


 In a program, I want to set some kind of variable or object to indicate what
 mode the program is currently in.
 What is the most elegant way of doing this?

 Jim
 ---
 constant: moving = m
 constant: inserting = i
 constant:jumping = j
 .
 .
 action = moving
 .
 .
 .
 if action == jumping:
 jumpSomewhere()
 elseif action == moving:
 moveSomewhere()
 elseif action == inserting:
 insertSomething()
 

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





-- 
b h a a l u u at g m a i l dot c o m
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How is tuple pronounced?

2007-12-11 Thread bhaaluu
Greetz!
On Dec 11, 2007 4:55 PM, earlylight publishing
[EMAIL PROTECTED] wrote:
 So it looks like most folks here and on the web are saying too-ple (rhymes
 with scruple or pupil... sorta).  That's the one I'll go with... now that I
 can say it it's time to get back to learning how to use em!

There is tuple packing and tuple unpacking! Wierd, eh?

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/python.index.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Can't Find Timed While Loops

2007-12-07 Thread bhaaluu
On Dec 7, 2007 2:36 PM, Scottie Hotchkiss [EMAIL PROTECTED] wrote:
 Disclaimer: I can't test this while I'm at work, but using

 while 1:

 instead of

 while time.time() - start  30.0

 would be better.

 In the former case if you press enter after time has run out, it won't
 print the time, in the latter you could potentially make a correct
 answer after time has  run out.

 Example: At 29.0 you answer
 raw_input awaits and you wait 5 minutes, then answer.
 It will still run the print statement. The loop started and it doesn't
 matter how long you wait, because it won't evaluate that until the loop
 starts again.

 But it may alright depending on what you are trying to accomplish.

 Just my 2 cents,
 S Hotchkiss

 Tutor Lurker


Okay! Here's a sample 30-second Adding Game using time.time()
and a while True: loop. The timing granularity isn't all that great.
Sometimes it times out 2 or 3 seconds past 30 seconds, but in
this case, it probably isn't a big deal. This has been tested with
Python 2.4.3 running on Linux kernel 2.6.15 from the vim editor!

#!/usr/bin/python
import random
import time

startNum = random.choice(range(1, 9))
score = 0

print #*65
print  *14,Welcome to the 30-second Adding Game!
print #*65
print  * 5,Instructions:
print  *10,You'll choose a number.
print  *10,You'll be given a starting number.
print  *10,Add the number you chose to the starting number,
print  *10,then keep adding your number to the sum until
print  *10,the timer runs out.
print  *10,You'll have 30 seconds.
print  * 5,
num2add = raw_input( Choose a number to add: )
print raw_input( Press Enter when you're ready to begin.)
print #*65
num2add = int(num2add) # interpolation
newNum = startNum + num2add
print  Start with the number , startNum
start = time.time()
while True:
if time.time() - start  30.0:
answer = int(raw_input( Enter your answer: ))
if answer == newNum:
 print  That is correct!  Keep going.
 score = score + 5
 newNum = newNum + num2add
 print  Your score is , score
else:
 print  That is incorrect.  Please try again.
 print  Hurry! You only have %2.1f seconds left!\
 % (30 - (time.time() - start))
else:
break

print  Buzzz!!! Time's up!
print time.time() - start
#print \n
print  Your total score was: , score


Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/python/index.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Still Can't Find Timed While Loops

2007-12-07 Thread bhaaluu
On Dec 7, 2007 10:41 AM, bob gailer [EMAIL PROTECTED] wrote:
 earlylight publishing wrote:
  Hello all,
 
  I now have my bit of code in while loop form and it works!  It's great
  but not exactly what I wanted to do.  I've been googling my heart out
  and I find lots of info on while loops and lots of info on timers that
  will execute an action AFTER a given interval but nothing on a timer
  that will execute an action DURING a given interval.  What I'd really
  like to do at this point in my game is have the player execute the
  loop for 30 seconds then have it print the final score and break.
  Does anyone out there have any code that'll do that?

 import time
 start = time.time()
 raw_input(Wait a few seconds, then press enter to continue.)
 print time.time() - start

 Does that give you a hint?

 You don't need a timer, unless you want to interrupt the user if he is
 not entering anything.

Cool snippet! So if the player is entering numbers to an adding game,
and he has to continue entering numbers for 30 seconds, then it could
be accomplished with something similar to this, right?

import time
start = time.time()
while 1:
raw_input(Press Enter Now!)
if time.time() - start  30.0:
print time.time() - start
else: break

Thanks! 8^D
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While Loops and Modules

2007-12-06 Thread bhaaluu
Greetings,

On Dec 6, 2007 12:44 AM, earlylight publishing
[EMAIL PROTECTED] wrote:
 Hello again to all the wonderfully helpful folks on this list.  Today I did
 my Google homework and I found this neat bit of code for a countdown timer.

 import time
 import threading
 class Timer(threading.Thread):
 def __init__(self, seconds):
 self.runTime = seconds
 threading.Thread.__init__(self)
 def run(self):
 time.sleep(self.runTime)
 print Buzzz!!! Time's up!
 t = Timer(30)
 t.start()

 I don't understand large chunks of it (don't know what threading, self, or
 __init__ mean) but that's not important at the moment.  It works and I will
 learn the vocab eventually.

That is a good start! Get it working first, then figure it out later. 8^D


 I also wrote this bit of code for a math challenge which comes in the next
 part of my game.

 import random
 startNum = random.choice(range(1, 9))
 newNum = startNum + 7
 score = 0
 print 'Start with the number ', startNum, '.  Then continuously add 7 to
 that number until the timer runs out.  You have 30 seconds.'

 answer = int(raw_input('Enter your answer: '))
 if newNum == answer:
 print 'That is correct!  Keep going.'
 score = score + 5
 print 'Your score is ', score
 else:
 print 'That is incorrect.  Please try again.'

 I understand this part just fine 'cause I actually wrote it myself.


A couple of things which may help you when you're testing/debugging
your programs:

type(object)
dir(object)

Play with those in the interactive interpreter to see what they do, for example:
 a = 7
 type(a)
type 'int'
 a = time
 type(a)
type 'str'
 import random
 dir(random)
['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random',
'SG_MAGICCONST', 'SystemRandom', 'TWOPI', 'WichmannHill',
'_BuiltinMethodType', '_MethodType', '__all__', '__builtins__',
'__doc__', '__file__', '__name__', '_acos', '_cos', '_e', '_exp',
'_hexlify', '_inst', '_log', '_pi', '_random', '_sin', '_sqrt',
'_test', '_test_generator', '_urandom', '_warn', 'betavariate',
'choice', 'expovariate', 'gammavariate', 'gauss', 'getrandbits',
'getstate', 'jumpahead', 'lognormvariate', 'normalvariate',
'paretovariate', 'randint', 'random', 'randrange', 'sample', 'seed',
'setstate', 'shuffle', 'uniform', 'vonmisesvariate', 'weibullvariate']

etc.

Another little trick I use to watch the values of variables and set breakpoints:

print variable_Name
raw_input(Pause)

I just insert those two lines after each variable I want to watch (perhaps
to see if it is actually doing what I think it is supposed to be doing?).


 What I need to do now is put these two parts together so that the player
 will keep adding 7 to the starting number for 30 seconds then the loop
 breaks.  I know I need a loop of some sort and I'm guessing it's a 'while'
 sort of thing.  I couldn't find what I was looking for when I Googled.  I'm
 not even sure I knew the right search terms.  Does anyone know how I'd
 combine these two modules to make it work?


while True: or while 1: do the same thing, and they are a generic infinite loop.
You can use the keyword break somewhere inside the loop to break out of it.

When you figure out what condition  must be met to quit the while loop,
you can replace the True or 1 with your condition.

For example, working with the snippet you supplied:
import random
import time
import threading

class Timer(threading.Thread):
def __init__(self, seconds):
self.runTime = seconds
threading.Thread.__init__(self)
def run(self):
time.sleep(self.runTime)
print Buzzz!!! Time's up!
t = Timer(30)
startNum = random.choice(range(1, 9))
newNum = startNum + 7
score = 0
t.start()
print 'Start with the number ', startNum, '. Then continuously add 7
to that number until the timer runs out.  You have 30 seconds.'
while 1:
answer = int(raw_input('Enter your answer: '))
if newNum == answer:
print 'That is correct!  Keep going.'
score = score + 5
print 'Your score is ', score
newNum += 7
else:
print 'That is incorrect.  Please try again.'

That isn't quite working as it should, but I only added a couple of lines
and did the requisite indentation for the while loop. It might be enough
to keep you going for a wee bit?

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Loops and modules

2007-12-06 Thread bhaaluu
On Dec 6, 2007 8:38 AM, richard west [EMAIL PROTECTED] wrote:
  heres a partial solution. theres no error checking on the Raw Input and you
 have to type in you last number and press return, before the loop will
 break, but its a start!

And modifying  your modifications makes it work even a little better:
###
#!/usr/bin/python

import random
import time
import threading

class Timer(threading.Thread):
def __init__(self, seconds):
   self.runTime = seconds
   threading.Thread.__init__(self)
def run(self):
global running
time.sleep(self.runTime)
print  
print Buzzz!!! Time's up!
running = False

t = Timer(30)
t.start()
startNum = random.choice(range(1, 9))
newNum = startNum + 7
score = 0
running = True
print 'Start with the number ', startNum, '.  Then continuously add 7
to that number until the timer runs out.  You have 30 seconds.'

while running:
if running == True:
 answer = int(raw_input('Enter your answer: '))
 if answer == newNum:
   print 'That is correct!  Keep going.'
   score = score + 5
   newNum = newNum + 7
   print 'Your score is ', score
 else:
   print 'That is incorrect.  Please try again.'
else:
answer = 0
print ' '
print 'Your total score was: ', score
###

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m

 #!/usr/bin/python
 # Filename : math_test.py

 import time
 import threading
 class Timer(threading.Thread):
 def __init__(self, seconds):
self.runTime = seconds
threading.Thread.__init__(self)
 def run(self):
 global running
 time.sleep(self.runTime)
 print  
 print Buzzz!!! Time's up!
 running = False
 t = Timer(30)
 t.start()

 import random
 startNum = random.choice(range(1, 9))
 newNum = startNum + 7 # im assuming you want the first number the user to
 type as the startnum +7,its not too clear.
 score = 0
 running = True

 print 'Start with the number ', startNum, '.  Then continuously add 7 to
 that number until the timer runs out.  You have 30 seconds.'

 while running:
 print running
 answer = int(raw_input('Enter your answer: '))
 if running == True:
  if answer == newNum:
print 'That is correct!  Keep going.'
score = score + 5
 newNum = newNum+7
print 'Your score is ', score
 else:
print 'That is incorrect.  Please try again.'
 print ' '
 print 'you total score was ', score

 On Dec 6, 2007 6:15 PM, [EMAIL PROTECTED] wrote:
  Send Tutor mailing list submissions to
 tutor@python.org
 
  To subscribe or unsubscribe via the World Wide Web, visit
  http://mail.python.org/mailman/listinfo/tutor
  or, via email, send a message with subject or body 'help' to
 [EMAIL PROTECTED]
 
  You can reach the person managing the list at
 [EMAIL PROTECTED]
 
  When replying, please edit your Subject line so it is more specific
  than Re: Contents of Tutor digest...
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Thanks (was Random Number Generator)

2007-12-05 Thread bhaaluu
On Dec 4, 2007 7:21 PM, earlylight publishing
[EMAIL PROTECTED] wrote:
 Thank you everyone for your help!  I have no idea why it never occured to me
 to Google it.  Thanks for the code.  Now let's see if I can get this sucker
 to work!


1) Wikipedia  -- learn a basic vocabulary so you can enter keywords into
2) Google  -- Feeling Lucky? If that doesn't work, sort through the other 200K
3) Python Tutorials  -- Get up and going quickly, saving the hard parts for
4) Python Documentation and Books

And then there's the Python Tutor list! 8^D

Best of luck getting your program working.
If you get stuck, show us your code, and error messages, we'll try to help.
(It also helps to add system info as well as Python version, etc.)
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] This is the online help utility [tutorial].

2007-12-05 Thread bhaaluu
Greetings,
Recently a thread about Python's online help utility was buried
within another thread with a different Subject. So I thought I'd
try to summarize that thread within a thread in a thread of its own.
It would be helpful for those running different versions of Python
on differnet systems to contribute their online help experiences
if they differ from what I'm posting. I'm running Python 2.4.3 in
bash, in a Konsole (KDE) running on the Linux 2.6.15 kernel.

1) Starting the Python Interactive Interpreter:

$ python
Python 2.4.3 (#2, Oct  6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type help, copyright, credits or license for more information.


It says to type help, so that's what I type:

 help
'help'

Oops! That doesn't work very well now, does it?

 help
Type help() for interactive help, or help(object) for help about object.

A! That's better. If I'm new to Python, I probably won't know what
'object' means
in help(object), so maybe 'help()' will be a good start?

  help()

Welcome to Python 2.4!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type quit.

To get a list of available modules, keywords, or topics, type modules,
keywords, or topics.  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as spam, type modules spam.

help

OK! The first thing I notice is that the interactive prompt has changed from
'' to 'help'.  There is some VERY USEFUL INFORMATION in the splash
text. For example, to get out of the help utility, and return to the
interpreter,
I need to type quit -- it can be typed WITHOUT the quotes!

Three other words are suggested for use here: modules, keywords, and topics.
So now I have four words I can use at the 'help' prompt to get help:
quit, topics, modules, and keywords.

help keywords
Here is a list of the Python keywords.  Enter any keyword to get more help.

and elseimport  raise
assert  except  in  return
break   execis  try
class   finally lambda  while
continuefor not yield
def fromor
del global  pass
elifif  print

help pass


  6.4 The pass statement

pass_stmt::= pass

  Download entire grammar as text.[1]
[snip]

On my machine, when the help has ended, END is displayed, and I must
type a q to get back to the help prompt.

help modules

Please wait a moment while I gather a list of all available modules...

ArgImagePlugin  UserListfpectl  qtxml
ArrayPrinterUserString  fpformatquopri
BaseHTTPServer  WalImageFileftplib  random
[snip]
Enter any module name to get more help.  Or, type modules spam to search
for modules whose descriptions contain the word spam.

help modules random

Here is a list of matching modules.  Enter any module name to get more help.

random - Random variable generators.
whrandom - Wichman-Hill random number generator.
_random
RNG (package) - x=CreateGenerator(seed) creates an random number
generator stream
RandomArray

Here again, when at the help prompt, no quotes are necessary around
the words entered.

help topics
 topics

Here is a list of available topics.  Enter any topic name to get more help.

ASSERTION   DELETIONLOOPING SEQUENCES
ASSIGNMENT  DICTIONARIESMAPPINGMETHODS  SHIFTING
ATTRIBUTEMETHODSDICTIONARYLITERALS  MAPPINGSSLICINGS
ATTRIBUTES  DYNAMICFEATURES METHODS SPECIALATTRIBUTES
[snip]

help POWER


  5.4 The power operator

  The power operator binds more tightly than unary operators on its left;
  it binds less tightly than unary operators on its right. The syntax is:

power::= primary[1] [** u_expr[2]]

  Download entire grammar as text.[3]
[snip]
:

The colon means I can type SPACE for another page, or ARROW key to move a line.
At the end, or at any time, I can type a q to return to the help prompt.

help quit

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type help(object).  Executing help('string')
has the same effect as typing a particular string at the help prompt.

  Ctrl-D
$

When I 

Re: [Tutor] info, help, guidence,...

2007-12-05 Thread bhaaluu
Greetings,

On Dec 5, 2007 10:30 AM, jeff witt [EMAIL PROTECTED] wrote:

 Hello,
 i have some questions about programming in general and python,..
 my brother (who is a programmer) guides me to .net languages,  and i am
 not too sure why, however, he is getting sick of me pestering him with my
 questions,..
 i like the little i know about python, it seems to be user friendly,
 however, i am not finding clear answers about what it does compared to
 .net for example.
  I really know nothing about programming (which i am sure is obvious) so ANY
 info would be helpful, ...

 here are a few questions that go through my head...
  how does python get applied to a GUI?

http://wiki.python.org/moin/GuiProgramming
TkInter is Python's standard GUI library

 why dont universities teach it? is
 there an online class i can take for it?  training certificates?   is it
 accepted in the world of programming professionally?  ( i am interested in a
 career too, as well as a new hobby),.

Some universities do use Python to teach Computer Science topics.
There are several online tutorials to get you started, for example:
http://docs.python.org/tut/
is the 'official' Python tutorial

   i use linux, and python seems to be everywhere for linux,.. and i read
 that it works on windows too but is it accepted in those circles?
 what is pythons strengths and weaknesses, IE. web/Internet, or program
 development, operating system things,...   what would you (or you guys)
 recomend for the first language?  or like my brother says, just learn
 something and stop asking me questions

Python is an excellent first programming language.
The Tutor list is for learning Python as a first programming language.
There seem to be an equal number of Tutors who use Linux or Windows.

 if python was released in 1991 how long will it remain a current or a
 applicable language? or i guess i am asking, what is the normal life of a
 programming language before it is obsolete?

That's a good question!


 well, like i mentioned, any help or info would be greatly appreciated,   i
 have been to some of the beginner sites and tried the whole hello world
 thing, and i unfortunately realize i am years from actually contributing to
 any open source project,  (especially since i am still struggling with the
 file system in linux [only been using it for 8or9 months])

 God bless you  guys, and thank you for your site and willingness to share
 and help!

 jeff

There are several excellent tutorials and books online for free.
You'll have to check them out and see which ones 'click' for you.
Each person learns stuff differently, and each writer has a different
'style' of writing, so you might find two tutorials that cover the same
things, but you'll like one better than the other.

This is a good place to ask questions!
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/python/index.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


  1   2   >