Well, the first thing you must do to write beautiful code is to make it readable. That is, take advantage of tabs and indenting, separate code sections like loops from other more mundane, like definitions or repetitive single-line orders... I've been messing with lots of code that essentially looked like a text brick, including that wrote by teachers. And then, starting with that you extrapolate, breaking everything into independent chunks of code, that are easy to understand by themselves, using properly named variables, constants, functions and all the usual suspects... Maybe you don't get beautiful code (I think the concepts clash a bit) but at least you'll get something attractive and easy to read and understand for other people, including yourself.