a step a little ahead, gui with python/Tk

July 2, 2008 at 6:57 pm (python) (, , , , , , )

I just started to write a very very VERY simple phonebook for my own use. This is just a quick note, and I will keep you posted with snippets here and there. this link helped me get through understanding how I would go about doing it. Anyway, I’ll get started now, will post snippets whenever possible!

Permalink 1 Comment

is that really prime?

June 25, 2008 at 10:41 pm (python) (, , , )

so, today I wrote my second python script ( big accomplishment ) which just lists prime numbers. I put it in a file called prime.py so I might be able to use it later on!! This is how it looks like:

====================================================

#printing a range of prime numbers

def isPrime( n ):
	factor = n // 2

	while factor > 1:
		if n % factor == 0:
			return 0
			break

		else:
			factor -= 1
	else:
		return 1

def listPrimes( num ):
	for n in range( num + 1 ):
		if n > 1:
			if isPrime( n ):
				print n, 'is prime'

listPrimes( 100 );

====================================================

and that’s all there is to it! Well, just add the indentation yourself, I still haven’t figured out how to keep the indentation when posting scripts!

hahahaha and on a side note, I had to check all of the output numbers myself ( not thoroughly though ) just to make sure I didn’t make any mistakes in the script! funny way of debugging.

UPDATE: thanks to a fantastic blogger, Vlad Dolezal ( anamazingmind.com ) I’m able to keep the formatting of the code!

Permalink 4 Comments