Hey-o, conditional statements! I breezed through a bunch of lessons because we’re getting back to the kind of programming that I have already learned quite well. For the novice, my blog will not be as helpful as it may have been for previous lessons. The issue is that I am super ready to finish LPTHW!
For Exercise 29, he introduces conditional statements, the results of which I could see as I typed them in.
people = 20
cats = 30
if people < cats:
print "Too many cats! The world is doomed!"
if people > cats:
print "Not many cats! The world is saved!"
Basic less-than/greater-than operators – clearly the world is doomed! That’s about all there is to this exercise. (Ed: T.I.L. that less than and greater than symbols have to be inserted into with & l t ; and & g t ;, respectively! Awesome!)
In Exercise 30, it’s the same thing but introducing, hmm, subconditional statements you might call them? Rather than just
else there’s also
elif which takes its place before the final
else in which you can make a further conditional statement within the
if statement. This has been one of the handiest things I have learned (though I learned it long before this lesson) in Python, and it has analogues in every other programming language as well. Very cool.
In Exercise 31, the conditional statements get wrapped up in a “game” in which your player gets to choose from various options, to either be driven mad by Cthulhu or ripped apart by a bear. HMMM, which would you choose?? The purpose of this lesson is to start getting the student comfortable with nested if-statements. Old hat for me – I need to move a little faster!
With that, I think I need to go through these lessons a little more quickly than I want to blog about. I will write another blog when I come up against something that is truly new to me. I know Zed Shaw has challenges for me yet!