PYTHON!

February 27, 2008

I am teaching myself python. I’ve gone too long without knowing a proper language (QBASIC doesn’t count), so I am learning python. Thanks to all the free documentation out there, and, here is my first program that does something:

# filename : area.py
def areasq(l, h):
global sqarea
sqarea = l * h
def areatri(l, h):
global triarea
triarea = .5 * l * h
while True:
shape = raw_input(‘Hello, what shape you do want to know the dimensions for?’)
if shape == ‘triangle’:
print ‘Oh, that’s nice’
l = int(raw_input(‘What is the length?’))
h = int(raw_input(‘What is the height?’))
areatri(l, h)
print triarea
elif shape == ‘square’:
print ‘Oh, that’s nice’
l = int(raw_input(‘What is the length?’))
h = int(raw_input(‘What is the height?’))
areasq(l, h)
print sqarea
print ‘I am sorry, that is not a shape that I am familar with.’
else:
break

I was trying to use a while, if, break, and def statements, and I think I did alright. I’m sure the code could be cleaner, maybe by putting the input section into a function, but it works! I’ll keep the internet updated, if anyone wants to follow the process of a geek learning code 🙂

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: