Well, it’s been a while since I attempted to blog. Yes, it failed. Maybe this time it will go ahead, we’ll see! Most the time my need to blog is brought on by a sudden interest in a new thing and I guess this time is no difference. Recently I have decided to teach myself Python. I guess it came about from a combination of “Hey, I would really like to expose myself to more programming languages and get good at a few” after my experiences with learning Java and C at uni this year. I’ve always wanted to learn to program but was never motivated to go out and teach myself. Now that I have the “basics” of programming down in Java and C I should be able to teach myself Python and other languages. Python was first on the list as a lot of UCC members use and love Python.
So far I haven’t looked that deeply at the language, only looking at the first few parts of the tutorial. I was successfully able to solve a problem introduced to me by one of my friends, shmookey, that was to find a “7 digit phone number” that has the property that exactly half the numbers before it contain the number 6. For those who care I shall put it below (assume correct indentation occurs…):
#! /usr/bin/python
#Count up from 10
c = 1
for i in range(10, 9999999):
n = i
while n > 0:
if n%10 == 6:
c += 1
break
n = n/10
if 2*c == i:
print ‘The phone number is: ‘ + i
break
Not a very difficult problem to solve but at least gave me a bit of an introduction to using Python. The first thing I noticed was that I had to remove all of my semicolons and braces, I think this will take a while to get used to. Once I had it all working I noticed that Python was much slower than I expected. While I did not expect it to have a blinding speed I still thought it would run much faster. I guess for simple number crunches like this I will just revert back to C. I wont give up on Python however, while I was disappointed with the speed at which it ran, I am surprised about how simple the majority of the syntax is.