Python and its different way of type casting

I tried to make a Fibonacci program in Python to experiment with getting user input, displaying output and type casting. This was the code that I came up with at first: 1 2 3 4 5 6 7 8 9 10 11 def fib(n): print 'n =', n if n > 1: return fib(n - 1) + fib(n - 2) else: print 'end of the line' return 1 n = raw_input('Input number: ') int(n) fib(n) When I tried running the program in the CLI, I have been successful in getting the user input....

November 1, 2010 · 3 min · 573 words

Optional Arguments, a gift from heaven

I’ve been messing around with functions in Python. One neat feature that I came across are optional arguments. Here’s some code that I’ve written to explain more about optional arguments: 1 2 3 4 5 def foo(length, bar = 5, foobar = 10): """A sample function demonstrating optional arguments. Takes 3 integer objects as its arguments""" print "Length is %d\nBar is %d\nFoobar is %d\n" % (length, bar, foobar) As with any other language out there, you can set default values for certain arguments in case they aren’t mentioned in a function call....

November 1, 2010 · 2 min · 232 words

The shortest 'Hello World' ever

I decided to start learning Python recently. I figured I should try learning something new outside the C-family of languages (C, C++, Java, C#, etc) just for kicks. Python seems like the perfect language to make that transition that I want since it is somewhere between C and non-C in terms of syntax. Since I have no idea how to start learning Python, I decided to ask a question on Programmers on Stack Exchange, which is a Q&A site that I visit most of the time....

November 1, 2010 · 2 min · 298 words

It all makes sense now

I hate high school. When I was still in high school, I was always included in the list of students who got the lowest mark in almost every class that I have. I’m not saying it’s because I’m stupid. Well, maybe that reason applies to some of my classes but the main reason why I always get low grades is because I hate all most of my classes. I have a strong belief that a class should be fun first before the student will learn....

September 26, 2010 · 3 min · 625 words

Don't worry, you'll get there eventually

The other day, I came across this thread on a forum that I’m lurking on. It reminded me of how I was literally asking the same question a few years ago. I’ve only been programming for a while (3 years isn’t considered long is it?). When I was still starting out, I have never been able to grasp programming for the first few months. Most of the time, I was even copying my classmate’s code just so I could have something to submit to my professor....

September 13, 2010 · 2 min · 344 words