Python: The Leap

*NOTICE Code Snippets cannot be seen on WordPress Reader, must be viewed on original site ammccann.com

forest-trees-fog-foggy

Went for a leap! Practiced a bit more formatting design with this one. Division and modulo spectacular. Now there are a few mistakes as I look back on this one. Some redundant or unnecessary code, but it still worked!

leapDay

What I found interesting about this one was really getting a handle on the modulo operator and it getting the remainder of a division problem and using it as a Boolean.

Speaking of modulo fun, Easter has an equation that was pretty tricky to get my head around.

easterPic

Now there were a few exceptions we had to account for with this specific problem, the exception years of ’54, ’81, ’49’, and ’76 which apparently factor a week late on the Easter date.

Now the ultimo calculator type we were to build in a homework exercise was this thing called Zeller’s Congruence, which is an algorithm developed to calculate the day of the week. The formula for this is:

zellerCongruence

Taking into account:

zellerCongruencerules

This had to be put into code which I translated into the following:

This one really helped get your head around some more complex equations for algorithms using the Python syntax.

zellerCongruencePic

Programming is much more useful than creating a bunch of calculators, but I think getting your head around things like binary, algorithms, and learning how computers compute is invaluable to learning logic.

Two last calculators, we had to build were a distance converter and a converter that would convert some days into weeks and days.

distanceConverter

Keeping the output basic, we are just focused on getting down the syntax.

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