Monday, October 3, 2011

Still easing into coding...

Okay, I'm not sleepy, so I'll keep going with Python tonight. So far it's still nothing new.

The next code is about learning modules. So here's our good friend random. Random has a function called randrange(n) which takes in an integer and provides a random number starting from 0 to n-1. So since this coding assignment deals with dice then you need to add 1 to the result from the randrange function. Seems simple enough.

Next is about branching and conditional statements. Now here's something interesting. Python recognizes blocks of statements by indenting. So Python forces you to indent if you want them in the same code block. Good practice in my opinion. I hated it when students would not pretty print their assignments, especially in Scheme when you're surrounded by an endless sea of parentheses. At least with Java and C++ you can bracket off areas, but even then you can get away with not indenting. Bravo Python. (I might hate it when I start doing more complex code). Oh fun! If-elif-else! Now that's some fancy naming (or lazy naming).

I guess I am getting tired for the night. I'll have to stop at the while statement and will have to code another night.
*Okay, I did a quick if elif piece of code. Yay for random song references!*




No comments:

Post a Comment