Monday, 14 October 2013

Middle of MidTerm

Oh happy day! Last week on Tuesday night I, Mackenzie Heller, against all odds, created a recursive method that worked! The solution? I deleted about half of my code. Turns out the 'solutions' I wrote for my bugs were in fact the problems themselves. I was unable to trust that if the program worked for the first case it could work for all cases thereafter. The program was handed in with one hour to spare. But now it's midterms, Ive been reviewing all the class notes and answering the preivous test we were given yet I still cant seem to get over the fact that I dont feel ready. I think thats because I havent really done any practice questions. A few questions on a practice test doesnt really seem like enough to me but maybe im just going overboard with how much i need to study for this (this being my first University test). In any case this is my answer for question 3...
def list_count(o):
    k = 0
    if isinstance(o, list):
        for i in range(0, len(o)):
            k += list_count(o[i])
        return 1 + k
    else:
        return 0
Im sure you could make it shorter but this is how it most logically makes sense to me.    

1 comment: