[Tutor] How to test for a remainder from division

2007-05-14 Thread Matt Smith
Hi there, I'm trying to write a short function to test whether a year is a leap year or not. To do this I need to check whether the year divides exactly by 4, 100 and 400. I can't think of an easy way to test whether there is a remainder or not. The best I can come up with so far is: if (year / 4

Re: [Tutor] How to test for a remainder from division

2007-05-14 Thread Matt Smith
Hi, Thanks for all the help, I guessed that there would be a module out there providing a function to do this but wanted to go through the process as a learning exercise. The modulus operator was just what I was looking for, I had been trying to check for a difference between the division and the

[Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Matt Smith
Hi, I am trying to write a simple program to display Conway's Game Of Life. I have the bones of the program together but I'm struggling with the function that tests for and applies the rules of the game (the important bit). I have the current state of the game stored in a 2d matrix with each cell

Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Matt Smith
On Fri, 2007-05-18 at 23:49 +0200, Rikard Bosnjakovic wrote: > Something like this: > > try: >the_index_outside_matrix_test() > except IndexError: > suppress_the_error() Thanks Rikard, I'm not sure how I would go about actually suppressing the error - what would suppress_the_error() actual

Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-18 Thread Matt Smith
> > Is there a better way of doing this? > > Perhaps something like this: > > for n in (x, x+1, x-1): > for m in (y, y+1, y-1): > if matrix[n, m]: > neighbour_count = neighbour_count + 1 > I need to not text matrix[x][y] is there a simple way to exclude this from the possible combi

Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-19 Thread Matt Smith
> the possible combinations of values from the two tuples? > see my other reply, Matt. > -Luke Hi Luke, Sorry if I'm missing something but which other reply? Matt ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Help with excetion handing and making my code more efficient needed please

2007-05-19 Thread Matt Smith
On Fri, 2007-05-18 at 17:03 -0500, Luke Paireepinart wrote: > see my other reply, Matt. > -Luke Apologies Luke, I have found your earlier post in the tutor archives - I don't seem to have received it from the list yet. Thanks for the help. Matt ___

[Tutor] Still having trouble with my game of life algorithm

2007-05-25 Thread Matt Smith
Hi, First of all, thanks to everyone who helped with my last post (http://mail.python.org/pipermail/tutor/2007-May/054360.html). I have re-written the function that applies the rules but it still doesn't return the expected result. I have been through it and corrected a couple of bugs bet as far a

[Tutor] More trouble debugging my game of life program

2007-06-03 Thread Matt Smith
d: #! /usr/bin/env python # Curses based Game of Life program # Written by Matt Smith import curses from copy import deepcopy def read_start(): # Read the starting configuration from a text file file = open('/home/matt/Python/game_of_life/r-pentomino.txt', 'r&

[Tutor] Suggestions for a first object orientated program

2007-06-03 Thread Matt Smith
Hi, I have been reading up on OOP in Python recently and feel ready to attempt my first program using OOP principals. Can anyone suggest a suitable first OOP project for me to get my teeth into? I haven't done any real GUI programming but I have started gutting to grips with the curses module und

Re: [Tutor] More trouble debugging my game of life program

2007-06-04 Thread Matt Smith
On Sun, 2007-06-03 at 18:09 -0400, Brian van den Broek wrote: > The first thing I would do to try to track down the problem would be > to try 15x30 and 30x15 matrices. If you have two cases where one > behaves as expected and one does not, it is usually very useful to try > to match the two cas

[Tutor] Invoking Python from Vim

2007-06-07 Thread Matt Smith
Hi, Bit of a Vim specific question this one but I hope someone might have an answer. I currently have the following line in my .gvimrc file (I'm using Ubuntu Linux): map :!gnome-terminal -e=python\ -i\ % This opens a window and runs the Python program I am working on. I don't really like the fa

[Tutor] How to keep trying something until it doesn't return an error?

2007-11-12 Thread Matt Smith
Hi there, I am currently working on a noughts and crosses program to try and teach myself some very simple AI programming and also to start to use OOP in Python. I am currently writing the framework for the game so I can then write a number of functions or a class to deal with the strategy sid

[Tutor] Use of sqrt() from math module

2007-12-01 Thread Matt Smith
Hi, I need to find the square root of a number in a program I am writing. I have imported the 'math' module so I thought I could just call sqrt(x) but I get an error message. Extact from my code and error message below. import sys, pygame, math ... if ypos >= 384 and velocity > 0:

Re: [Tutor] Use of sqrt() from math module

2007-12-01 Thread Matt Smith
Matt Smith wrote: > import sys, pygame, math > > ... > > if ypos >= 384 and velocity > 0: > impactvel = sqrt(velocity ** 2 + (2 * gravity * (ypos - 384 * > 160))) > > ... > > > Traceback (most recent call last): > File "",

Re: [Tutor] Use of sqrt() from math module

2007-12-01 Thread Matt Smith
Michael H.Goldwasser wrote: > After using "import math" you will need to use the qualified name > math.sqrt(blah) to call the square root function. That explains the > NameError when trying to use the unqualified name, sqrt. > > As to your first message, the ValueError that you are reporting wit