Python MOOC – Week 2

I’m going to sum up the experiences of the past week and share what I managed to find out.

First off, I really like the way the MOOC is organised. Especially the way it encourages team work and p2p-learning process. First the instruction was to sign up for OpenStudy, which is very good in terms of mutual help and revision. But there’s a problem there. You can ask questions there alright, but you can ask only one question at a time. That is, after you asked your question, it appears on the questions wire and everyone can see it and answer it. But if you want to ask another question, you’ll have to mark the current one as ‘closed’ and only then you’ll have an option to ask a new one. ‘Closed’ means that it is removed from the wire shown by default (to the list of closed questions) and if you haven’t received the answer so far, there’s a chance you’ll never have it because nobody will notice the question.

2013-06-30 20_32_53-OpenStudy

Ah yes, also OpenStudy is often down, so you sometimes simply can’t use it.

But there are great options outside. First is that the MOOC organisers divided all MOOCsters into teams and provided them with mailing list addresses, so some questions cans be asked and answered in small groups and you have no limitations here.

Finally, there’s one more learning space I discovered only yesterday and haven’t tried yet, but it looks great. I mean Groups at Codecademy (you have to sign in to see the page). Although I’ve been using Codecademy for quite a while now, I didn’t know about their existence. Of course I immediately joined Python for Beginners group. I hope it’ll be a great experience.

Now a couple of words about this week’s homework. This week was rather challenging for me, because I was struggling to understand how loops work, especially the for loop. One of the tasks was to write a code that calculates exponentials using a for loop. Thanks to my team mates who helped me figure out what the task was about in the first place  – that is that the task should be executed without using the in-built exponentiation (**) option.

Now, I had dealt with for loops at Codecademy and found them rather easy. This is what I basically imagined:

for i in range(1, 10, 2):

    print i

So it does what you tell it to with all the items in a range.

But in this case a possible resulting code I got after many efforts (and quite a bit of guesswork, I admit) looks like this:

base = input("Enter base: ")

exp = input("Enter exponent: ")

x = base

for n in range(1, exp):

    x *= base

print x

So after I wrote it, I still had a question: how are for n in range(1, exp): and x *= base connected if there are no obvious operations in which n (the items from the range) are mentioned? The answer is obviously that they don’t have to be mentioned. That is, the for loop in this case is used to show the computer how many times the operation must be repeated.

This is what I realised after reading this awesome article about loops in Python. And I also realised that there’s a great way to see what programme does by adding print statements that reflect the process step by step. Like so:

base = input("Enter base: ")

exp = input("Enter exponent: ")

x = base

for n in range(1, exp):

    x *= base

    print x # This shows what's going on in the process

print x

So for instance if we have base 5 and exp 4, the output will be:

25

125

625

625

Also one of my team mates kindly recommended me to read Learning Python by Mark Lutz (I found out on the way that there’s a whole site about it).

Finally, I played with PyScripter IDE and explored some code sharing options, which I’m going to describe soon.

Oh, by the way, if some peers want to have a look at my whole homework (with the exception of optional tasks I’ll get back to them a bit later), it’s here: https://gist.github.com/ansakoy

Python MOOC – Week 1 UPD

I know by experience that ‘next week’ is always full of unpredictable work, sudden meetings and other distracting stuff, so I decided to do my best at the weekend to play with Python. Kudos to Codecademy, once again. The first week’s homework was really easy (but good for revision), while only a month ago I’d feel totally frightened by it.

Just tried out OpenStudy. I was absolutely resolved to be using IDLE for the rest of my life the course, but one peer there endorsed another IDE (Interpreted Development Environment) called PyScripter. So I went and checked it out. Not that at my level it made a huge difference, but I like it that PyScripter has a compact layout that works in one window instead of two, unlike IDLE that has separate shell and text editor.

PyScripter:

2013-06-23 19_19_51-PyScripter - module1_

 

IDLE:

 

2013-06-23 19_21_19-Python Shell

 

I think I’ll try using both and see which is best for me.

Also we had an illustrative task in natural language processing (exercise 1.11). We were given a sentence Alice saw the boy on the hill with the telescope. And we had to sketch the two possible interpretations of this sentence. Drawing in MS Paint with a mouse – what a pleasure!

Exercise 1