Friday, 26 February 2016

CSC148 Week 6

Reading week is over! I honestly wish it was longer, but at least I was able to catch up on sleep.

We started talking about recursion this week. Recursion is a technique in which a method is used within itself. The method is executed many times times (within itself) in order to keep changing certain data. Recursion can be used to make beautiful visuals such as fractals. To have a method work within a method is pretty mind blowing!

We also learned about the one liner version of an if else statement. Here's an example below:
>>> z = 100
>>> z = 10 if z == 100 else print('banana')
>>> z
10

I found the syntax of the one liner version to be confusing at first. It took me a lot of typing in python shell to figure it out/understand it. The above statement literally means: I want z to equal 10 if the expression z == 100 is true, or else print the string 'banana'.

No comments:

Post a Comment