## Geek level up!

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

else:

print ‘The circumference of you ‘ + str(sides) + ‘-sided polygon is ‘, sides*length

## Leave a Reply