Python Rocks man!!

September 8, 2008 at 9:59 am (Uncategorized) (, , )

Its been around 30 minutes since i have been using python. I downloaded this pdf ebook written by Swaroop C H from dgplug.org. Its hard to believe how easy it is to learn  Python. I have been sweating a lot over C++ lately, and this looks like a piece of cake.

One of the first programs i tried was converting a number to the base of 10 to a number of any base as input by the user. Here it is:

#!/usr/bin/python
#converts number to the base ten to number to any base
def recurse(n,b):
  if n>=1:
    m=n%b
    recurse(n/b,b)
    print m
  else:
    quit

i=int(raw_input("enter a number:"))
b=int(raw_input("enter base:"))
recurse(i,b)

I love this program because it creates small code using recursion logic, and i came up with this solution in my first year of college when a friend asked me casually about it. It rocks even more in Python!

Advertisements

5 Comments

  1. Enrique Mogollan said,

    I use to have the same problem for the indentation, but I found: http://dpaste.com. You could try it for getting a nice HTML for your code.

  2. Debayan said,

    @Enrique
    Thanx a million 🙂

  3. Sayamindu said,

    I am currently writing a parser using Python, and I cannot believe how easy it is :-). Maybe you would want to do some of your OCR stuff in python ? 😉

  4. debayan said,

    @Sayamindu
    Sounds like a nice idea.

  5. Shreyank Gupta said,

    Told ya! 😀

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

%d bloggers like this: