2015年1月31日星期六

Slog week 3

Slog 3

In class we learn about turtle still, and it was amazing, but I never tried to do it by myself. This week I focused on doing assignment. Our prof explained may questions about our assignments. We had a better understanding about how to divide the project into different classes and the different between generic and specific. 


I was thinking to divide the subtract square game into 3 class: game_state, game_strategy and game view. However, in to lecture prof told us we need to design generic class so that we can use it to the next two assignments. So I changed the 3 classes in to five classes: generic_game, subtract_square, generic_strategy, specific_strategy, and game_view. 

slog week 4

slog week 4

In this week’s lecture I learned about recursion. We use sum_list to example and trace it to learn recursion. 

def sum_list(L):
’’’ (list or int) -> int
Return L if it’s an int, or sum of the numbers in possibly nested list L
>>> sum_list(17)
17
>>> sum_list([1, 2, 3])
6
>>> sum_list([1, [2, 3, [4]], 5])
15
’’’
I think the code of recursion for this example should write as:
return sum([sum_list(x) for x in L])
However, I ignored the type of the list, we need to use:
if isinstance(L, list): to see whether L is a list or not.
and if L is not a list, we need to use:
else: # L is an int
return L

I did pretty well in the class worksheet’s question. However, I did figure out the lab question.

In the lab I follow the instruction sheet to do the 4 examples first. The third example nd(L), was really hard. Other than the examples given by the instruction sheet, I create several example to trace nd(L), such as [[3,3],[4,[4,5]]], and [[3,3],[4,[4,[3,3,[4,4]],5]]].


Although I did not finish the lab, I feel I could do better about recursion.

2015年1月23日星期五

Week 2

Week 2 
During this week’s lecture, I learned about turtle. I was amazed when I saw the perfect square and the perfect triangle showed on the screen. It is the first time I thought about python could do a lot of things way more interesting than just get a list of students name or make dictionary. However, the class material was confused at first. I could follow the lecture in the first hour. I kept reading the code of ‘Shape’ and ‘Square’ again and again, and tried some code by myself. Then I felt a little confident. From the last week’s lecture I couldn’t figure out what a subclass is. But in this lecture I understand how to make a subclass. 

For example, the main class is ‘Shape’, the subclass is ‘Square’, in python the subclass should be written as ‘Square(Shpae)’. Also, we can use ‘raise NotImplementedError('Need a subclass’)’ in main class, and rewrite the function in subclass.

It is extremely interesting when our prof using the tory to make the move. I think this is a really good way of teaching us the new concepts. I searched online about turtle. There are a lot of material related to turtle. I am a little afraid that I cannot use turtle as skilled as we should do. But I will rewrite the ‘Shape’ and ‘Square’ python code so that I could learn the material better.


The tutorial material was as hard as usual. We need to design 3 classes in order to get the GPA of the course according to the letter grade and the numeric grade. Anyway the lecture was fun and the material was interested. 

1/23/2014