Recursion is most effective in problems that involve multiple layers of similar problems. A recursive function will have a base case with a return value, and some way of calling itself. When started it will call on itself until it reaches the base case, then continue solving the problem upwards from there.
Alternatively: http://lmgtfy.com/?q=Recursion
Christiaan's 148 SLOG
Sunday 2 March 2014
Sunday 9 February 2014
Week 5: Name scopes
This week we covered name spaces/scopes.
There are several scopes of name spaces.
Built-in: always present
Global: names in current module of __main__, so likely will be present until the interpreter closes.
Non-local: basically any name used within a function that isn't local to that function.
Local: found in function bodies, will be lost when that function terminates.
Assignment one was easy enough up until part 5, where my brain decided it had had enough and neglected to point the obvious answer. After completing the recursive part of step 5 the rest of the assignment was once again easy and I finished fairly quickly.
Also, pep8 insists on making my code look bad. Sad face.
There are several scopes of name spaces.
Built-in: always present
Global: names in current module of __main__, so likely will be present until the interpreter closes.
Non-local: basically any name used within a function that isn't local to that function.
Local: found in function bodies, will be lost when that function terminates.
Assignment one was easy enough up until part 5, where my brain decided it had had enough and neglected to point the obvious answer. After completing the recursive part of step 5 the rest of the assignment was once again easy and I finished fairly quickly.
Also, pep8 insists on making my code look bad. Sad face.
Thursday 23 January 2014
Week 3 - Object Oriented Programming
OOP is the only type of programming language I have ever used, with experience in Java and Python. It is a style of programming that, obviously, is based on objects. Objects are an instance of a class, so they can hold data (variables) and contain functions (methods) to change that data or to perform other tasks, often based on the data contained in the object. Usually objects have an interface to interact with their variables, meaning methods to set change and/or retrieve their values.
Subscribe to:
Posts (Atom)