Sound and Fury

Signifying nothing

Geek level up!

leave a comment »

So I’ve decided to learn Python. Why? because I can. And because I want to make a program that can calculate digits of pi and then analyse the relative frequency of various digits. Possibly in various counting bases (binary hex etc) I’ve got as far a writing a program that asks for a number of sides and a length and computes the circumference of the shape, and tells you what shape it is (up to dodecagon).

I feel I am increasing my maths geek and computer nerd levels at the same time. Score!

In other news, I am going on holiday tomorrow, which sort of scuppers my plans of learning Python. But I will be back beginning of August and I will get cracking then.

Here is the code for my program, if anyone is terribly desperate for crap Python code…

shapearray = [‘triangle’, ‘square’, ‘pentagon’, ‘hexagon’, ‘heptagon’, ‘octogon’, ‘nonogon’, ‘decagon’, ‘undecagon’, ‘dodecagon’]
sides = int(raw_input(‘Enter the number of sides: ‘))
while sides < 3:
sides = int(raw_input(‘A shape must have at least 3 sides. Try Again: ‘))
length = int(raw_input(‘Enter the length of each side: ‘))
while length <= 0:
length = int(raw_input(‘Side length must be a positive number. Try Again: ‘))
if sides <= 12:
foo = 0
while foo < sides-3:
shape = shapearray[foo]
foo = foo + 1
print ‘The circumference of your ‘ + shapearray[foo] + ‘ is’, sides*length
print ‘The circumference of you ‘ + str(sides) + ‘-sided polygon is ‘, sides*length


Written by Seamus

July 13, 2007 at 1:26 pm

Posted in maths, python

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: