[Tutor] First program

Luke Paireepinart rabidpoobear at gmail.com
Fri Mar 12 11:30:10 CET 2010

On Fri, Mar 12, 2010 at 4:03 AM, yd <ydmt923 at gmail.com> wrote:

> Hi,
> I am new to programming, altough i have read a few books about OOP and
> O'Reily's Learning Python.
> I would like some critique on my first program, is it normal for it to be
> this long to do something simple?
> I know i could have turned some of these things into classes and functions
> but i don't know how to do that yet.
> Some critique of the algorithm and writing style or anything in general
> would help and any pointers would be appreciated.
> Thanks.
> One thing you should do is use more indentation.  Your program structure is
VERY hard to read with single space indentations.  Consider using 4-spaces.
This is not overtly long, I would say it's reasonable for a first program.
There are some things that you could probably group together, though.
Remember that code reuse is one of the core tenets of computer programming!

One example: area of square, parallelogram and rectangle are all the same.
You could do something like this (assuming user enters strings as choice
(rather than ints)):
if choice in ['rectangle', 'square', 'parallelogram']:
    height = int(raw_input("Height: "))
    if choice != 'square':
        width = int(raw_input("Width: "))
        width = height
    print "A %s with dimensions %sx%s has an area of %s." % (choice, height,
width, width*height)

Similarly with Ellipses and Circles, you can group some stuff together.

One thing, though.  Most people are still using Python 2.6 (which is what my
example above is in) and you appear to be using 3.0.  Perhaps you should
learn on 2.6 first, there are more resources and libraries available than
for 3.x at the moment.

I could probably make more comments but it's late and I need to go to bed,
hopefully that's a decent enough start.

Also (just FYI - you didn't do anything wrong) when replying to a post
please use "reply-all" so that the group will get the message.  If you use
"reply" it will just come straight back to me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100312/5c885ada/attachment-0001.html>

More information about the Tutor mailing list