# Foundations of programming (CK0030)

The course overviews introductory topics in computer programming using Python (primarily 2.7.x) and examples from mathematics and natural sciences. The main bulk of covered material consists of the following topics:
1. Introductory technicalities: Getting Python, writing and executing programs;
2. Basic computations: Programs, variables and computer arithmetics;
3. Loops and lists: WHILE-loops, lists and tuples;
4. Functions and branching: Functions, arguments and variables, IF-ELSE blocks;
5. User input/output and errors: Input reading and output writing, exceptions;
6. Array computing and plotting: Arrays, curve and field plotting.
If time allows, the following topics will also be briefly discussed
1. Introduction to classes: Function classes, methods and attributes;
2. Object-oriented programming: Inheritance and class hierarchies.

Instructor : Francesco Corona (FC), francesco döt corona ät ufc döt br
Teaching assistant : Rafael de Oliveira e Lima (RL), rl ät ask döt him

Physical location : Tuesdays and Thursdays 08:00-10:00. Bloco 951, Sala 01.
Internet location : Here! Or, here (CK0030) for mambojumbo related to administration.

Evaluation : Approx. half a dozen theoretical and practical problem sets will be assigned as homework. In general, home assignments will be considered equivalent to partial evaluations (APs). The final grade is given by the weighted sum of the grades in the individual assignments (all grades have the same weight, unless stated differently). If a topic need be evaluated through both homeworks and a classrom AP, then the homeworks will be given weight 0.4 and the AP weight 0.6.

If needed, a final evaluation (AF) will be arranged.

- The operator AVG() denotes the average (arithmetic mean) of the objects between round brackets ();
- EX01 is the grade from this exercise set
- EX02 is the grade from this exercise set
- EX03 is the grade from this exercise set
- EX04 is the grade from this exercise set
- EX05 is the grade from code discussion (A failure to turn up automatically grants 0/100 points)

Final grades: Students with grades between 4 and 7 are entitled to have a final evaluation (AF, see below).
- AF (MAX four questions) is Tuesday July 18 - 08:00-10:00 - Sala 01, Bloco 951.
- Please, send email to FC to confirm participation and minimise printing.

Go to:   Lectures and schedule | Problem sets | Supplementary material | As it pops out |

## News

>>>>>> Final scores <<<<<< Grades between 4 and 7 are entitled to have a final evaluation (AF, see below).
>>>>>> Final evaluation <<<<<< Tuesday July 18 - 08:00-10:00 - Sala 01, Bloco 951

>>>>>> Code discussion: Schedule (JUN 04 and JUN 06) <<<<<<

>>>>>> Avaliação Institucional 2017.1 <<<<<<

>>>>>> PIBIC 2017/2018 - 1 Position @ CC/DC <<<<<<
>>>>>> PIBIC 2017/2018 - 2 Positions @ CT/DETI <<<<<<

## Lectures and schedule

We meet on Tuesday March 14 at 08:00 (give or take 5), to briefly introduce each other and discuss practicalities.
MAR 14, MAR 16, MAR 21 and MAR 23 (cancelled, due to apparent faint of the TA)

 A Introductory stuff (FC and RL) Slides Generalities about the course Technicalities about setting up a Python ecosystem

2. Basic computations
MAR 28, MAR 30 (cancelled, Encontros Universitários 2017), APR 04 and APR 18

 A Computing with formulas (FC) Programs and programming, writing and running code Variables, comments, text formatting and numbers Arithmetic operators, integer division and objects B Interactive computing (FC) The shell, IPython, notebooks, ... C Complex numbers (FC) Complex arithmetics and complex functions D Symbolic computing (FC) Differentiation, integration, equation solving, series ...

Slides (last updated, APR 18) and Notebook
Exercises (last updated, APR 12 | APR 11, RL) Hand-in by APR 23 (was APR 20) at 23:59:59 Fortaleza time
Results (wrong scores here)

3. Loops and lists
APR 20, APR 25, APR 27, and MAY 02

 A WHILE-loops (FC) Definition, naive and efficient solutions, Boolean expressions B Lists (FC) List operations, sublists, FOR-loops, nested lists, tuples

Slides (last updated, MAY 12) and Notebook (last updated, MAY 12)
Exercises (last updated, MAY 11 | MAY 4 and MAY 9, RL) Hand-in by MAY 16 (was MAY 14) at 23:59:59 Fortaleza time
Results (wrong scores here)

4. Functions and branching
MAY 11, MAY 16, APR 18, and MAY 23

 A Mathematical functions (FC) Math functions as Python functions, local and global variables, arguments and returns Keyword arguments, DocStrings, Lambda functions B Branching (FC) IF-ELSE loops and inline IF-tests

Slides (last updated, MAY 24)
Exercises (last updated, MAY 29 | MAY 25, MAY 30 and JUN 01, RL) Hand-in by JUN 04 at 23:59:59 Fortaleza time
Results

5. User input/output and error handling
JUN 06, JUN 08 and JUN 13

 A User input/output (FC) Slides (last update, Jun 11) Reading from the command line, EVAL and EXEC functions Reading from file, writing to file B Error handling (FC) Slides Exception handling and raising C Modules (FC) Making, testing, using modules

Exercises ( JUN 20, RL) Hand-in by JUL 02 at 23:59:59 Fortaleza time

6. Array computing and plotting
JUN 27 and JUN 29

 A Vectors and arrays (FC) Slides Definitions and basic operations in numpy Allocation, generalised indexing, shape manipulation B Curve plotting (FC) Matplotlib (MATLAB-style and Pyplot prefix) Function vectorisation C Linear algebra (FC) Inverse, determinant, eigenvalues, products, norms Extreme values, transpose, lower/upper trangles Linear systems, row/column operations Symbolic linear algebra D Plotting scalar and vector fields (FC) Surface plots, parameterised curves, contour lines The gradient vector field

[Top]

## Problem sets

As we use problem set questions covered by books, papers and webpages, we expect you not to copy, refer to, or look at the solutions in preparing your answers. We expect you to want to learn and not google for answers: If you do happen to use other material, it must be acknowledged clearly with a citation on the submitted solution.

Homeworks must be done individually: Each of you must hand in his/her own answers. In addition, each of you must write his/her own code when requested. It is acceptable, however, for you to collaborate in figuring out answers. We are assuming that you take the responsibility to make sure you personally understand the solution to any work arising from collaboration (though, you must indicate on each homework with whom you collaborated).
We are likely to request you to defend the content of your homeworks.

To typeset assignments, you are encouraged to use this LaTeX template (to be updated): Source (PDF).

Assignments must be returned before deadline via SIGAA (you'll get notified of the opening of a new task) or, if you're not in SIGAA, return via email to one of the responsible teaching assistants.
Delays will be penalised (<24h, -20% of the grade; <48h, -40% of grade; ...).

[Top]

## Material

Course slides and notebooks will suffice. Slides and notebooks are mostly based on the following textbook:
• A primer on scientific programming with Python: 4th and/or 5th Edition, (Book website) by Hans Petter Langtangen.
Other primary references are the official Python documentation website (with tutorials, library and language references) and the many Python books, among which the following ones are related to this course:
• Python essential reference by D. Beazley
• Learning Python and Programming Python by M. Lutz
• Computing with Python - An introduction to Python for science and engineering by C. Fuerher, J. E. Solem and O. Verdier
Copies of the books are floating around.

>>>>>> Course material is prone to a typo or two - Please inbox FC to report <<<<<<

Top

Top