Learning Python From Scratch

I’ve been learning Python for about a week now using Learn Python the Hard Way. It isn’t that hard for me yet since I have a strong SysAdmin background. So it comes somewhat natural for me.

LPTHW is not the best resource for a beginner but it’s a great start nonetheless. Previously, I haven’t written any code beyond Hello World and today I was able to write a program that determines your age.

While it’s nothing complicated, I do find it very encouraging to create something from scratch.

# Function to find current age.
def find_age(current_year, birth_year):
 print "Subtracting %d - %d" % (current_year, birth_year)
 return current_year - birth_year

# Get input from user for the current calendar year. 
print "What year is it now?"
current_year = int(raw_input("> "))

# Get input from user on the year they were born.
print "What year were you born?"
birth_year = int(raw_input("> "))

# Create a variable of the user's age.
age = find_age(current_year, birth_year)

# Display the user's age after calculation.
print "You are %d years old." % age

This is the result of the code:

What year is it now?
> 2013
What year were you born?
> 1990
Subtracting 2013 - 1990
You are 23 years old.

The next step for me is to continue the exercises from LPTHW and then move onto another learning resource.

Related Posts

About Rowell Dionicio

I am Rowell Dionicio, a network engineer with a coffee addiction, an advocate of WordPress, with a passion about networking and wireless. I am part of the Cisco Champion program and my purpose is to help you become a better engineer. Follow me on Twitter, LinkedIn, Facebook and YouTube.

  • orchard cms

    This is a well written article on this subject. Your post is very nice, i appreciate your professional way of
    writing this post. Good job on this writing up!orchard cms

  • http://www.freetemplatesonline.com/ Stacy

    Cool! thanks for this article