Programming Fundamentals with Laboratory

Course objectives

General objectives: Introduction to programming with the Python programing language. Specific objectives: Introduction to programming through the Python language. Data types, variables, assignments, control structures, functions, classes, modules, and Input/Output. Data structures: arrays, strings, lists, tuples, and dictionaries. Design and development of programs through procedural programming and object-oriented programming. Recursive and iterative algorithms. Python libraries for graphics, file handling, text/html processing, and internet access. Program debugging and testing with Spyder as IDE and ipython. Problem Solving and Understanding of a problem: Understand and define a problem's requirements. Choose how to represent the input and what data structures to use for intermediate computations and output. Define the algorithm solving the problem. Code the algorithm as a Python program. Modularize the program as small separate functions/methods. Test that the program satisfies the requirements. Apply knowledge and understanding: Students will work at home on a series of programming tasks, throughout the whole course, to practice and to show what has been learned. At the end of the course, the exam will be based on a lab test where they should solve and program various programming exercises. Critical and judgmental skills: At the end of the course, students should be able to autonomously choose how to solve a programming task (analysis, implementation, and test). Communication skills: Students must have good text comprehension abilities for the problem analysis and requirement definition phase. Learning ability: The ability to analyze a problem to define its requirements and design both the necessary data structures and the correct algorithm will apply to other programming languages and will be very useful for the following programming courses.

Channel 1
PAOLO GASPARE BOTTONI Lecturers' profile

Program - Frequency - Exams

Course program
Introduction to programming through the Python language. Data types, variables, assignments, control structures, functions, classes, modules, and Input/Output. Data structures: arrays, strings, lists, tuples, and dictionaries. Design and development of programs through procedural programming and object-oriented programming. Recursive and iterative algorithms. Python libraries for graphics, file handling, text/html processing, internet access, symbolic calculus and data analysis. Program debugging and testing with Spyder as IDE and ipython.
Prerequisites
Basic knowledge of mathematics and set theory
Teaching mode
Classroom classes and laboratory hands-on
Frequency
Participation in classes is strongly advised.
Exam mode
The exam will be centred on topics considered in the lessons and will be completed with practical tests. Specifications of programming problems will be available throughout the year. The exam will preliminarily evaluate the ability to solve them.
Bibliography
Charles Dierbach - Introduction to Computer Science Using Python: A Computational Problem-Solving Focus Python 3 Tutorial - https://docs.python.org/3/tutorial/ Paul Deitel, Harvey Deitel - Python for Programmers, Deitel Developer Series Paul Deitel, Harvey Deitel - Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud, Deitel Developer Series More information on: https://iacopomasi.github.io/fdp Other useful tools:PEP 8 - Style Guide for Python Code - How to write elegant code in python - https://www.python.org/dev/peps/pep-0008/ PEP 257 - Docstring Conventions - Documentation of functions with docstring - https://www.python.org/dev/peps/pep-0257/
Lesson mode
Classroom classes and laboratory hands-on
PAOLO ZULIANI Lecturers' profile

Program - Frequency - Exams

Course program
Introduction, manipulation of strings and files: - introduction by the teacher, python motivation; - recap on mutable, immutable objects, passage by reference; - encoding and decoding; text files, open, with, read, readline, readlines, write, context manager; - binary files, work with bits and bytes, save an integer on a binary file, convert "by hand" with python binary to decimal, endianness; - hints to the manipulation of strings; Functional programming and iterators: - functions as objects, passing functions to functions, returning functions; - Iterators and Generators such as eager and lazy evaluation; - pack and unpack operators; functions with variable arguments args, kwargs; - functional programming in python (map, filter, any, all, lambda functions); - short example of using zip () iterator to join two files; Matrices and Images: - Definition of Matrix; - Matrix as a list of lists; - Create Matrices (various methods; from double cycle to functional with map); Compound Object; Difference between Shallow and Deep Copy; - Images as matrices; RGB color space; reference system with matrices; - Draw on images/matrices (draw lines aligned to the axes, rectangles, control to draw inside the matrix); - Outline of image manipulation (flip concerning vertical and horizontal axis, iterative and functional); Images, Image, and Object Manipulation: - Enumerated and zip clarifications - More on image manipulations, vertical and horizontal flip - PEP 8 (code style) and PEP 257 (docstring) - Rotate an image, clockwise and counterclockwise; transpose a matrix; iterative and functional versions - Blurring filter - Application case: how to blur only background similar to the "Zoom" filter and similar - Object-oriented programming - Objects and classes in python; inheritance - Example to model a color not as a tuple but as a class More on object-oriented programming - Review of what a class is; what is an object, attributes, and methods; classes in Python - Subclasses, inheritance, operator overloading - Class attributes and object instance attributes; class methods - Brief notes on Decorators in Python (@classmethod) - Exception handling in Python, try-except finally construct. Homework, Overloading, and Recursion: - Clarification on operator overloading __eq__ - Package and module in python; how python looks for modules; sys.path - Image processing «library» with objects as a package to use - Use of decorators to streamline the code - Library analysis and digression on design choices - The concept of recursion; queue and stack data structures; stack of a program - Recursive Fibonacci and recursion tree Fibonacci and recursive functions - Details on how to deal with HW - Complexity of naive Fibonacci (naive, basic version); exponential growth, an example of wheat grains on a chessboard - Fibonacci with "memoization"; hints on dynamic programming (DP); Iterative Fibonacci - Subproblems + base case; divide and conquer - callable objects in python and the overloading of __call__ - Example of using recursion to print a string without for loop - Hints to the filesystem as a recursion tree Various examples of recursion: - Brief mention on not modifying modules in the HW - [Recursion] Summarize how to print string character by character without for - [Recursion] Return and Pass Expressions - [Recursion] Filesystem as a recursion tree - [Recursion] Palindrome string (iterative, recursive) - [Recursion] Binary tree, tree search, pudb debug of the search Trees and research in depth: - Study philosophy and exam preparation - How to create an iterator to the imagemat class to model arrays - Short recap of Iterator, Iterable, Generator; functions with variable arguments (args, kwargs) - [Recursion] Enumerate (and get) the permutations of a set as a recursive problem - [Recursion] DFS depth-first-search (pre / in / post order) on binary tree - [Recursion] Arithmetic expressions as binary tree (browse them in pre / in / post) Homework: - Strategic advice on how to deal with HW and manage time - Analysis of the HW6 problem and possible ways to solve it, various ideas and solution schemes - Analysis of the data provided - Review of images / matrices as a list of lists (difference between row and column access) - Importance of how you write the code and its style - Notes on DAG (Direct Acyclic Graph) Artimetic Expressions such as Binary Tree - Review on callable objects - Review of images / matrices as a list of lists (difference between row and column access) - Importance of how you write the code and its style - Notes on DAG (Direct Acyclic Graph) Arithmetic Expressions such as Binary Tree - Review on callable objects - Review on * args, ** kwargs - Our defaultdict (use with care and caution) - Additional clarifications on TraceRecurision (based on __call__) - Arithmetic expressions as a binary tree - Concept of parser and grammar - Create a parser for arithmetic expressions with binary tree - Parenthesis management - Management of expression and split in tokens - Complete parser of Arithmetic Expression - Resolution and Print of in-order expressions Game Trees: - From Binary tree to N-ary tree - Branching factor of a tree - Review of the Filesystem as an N-ary tree with variable branching factor - Recap Recursion for calculating permutations, but with branching factor and complexity analysis - Game Tree: Node: State = Arc: Move; Game tree as an N-ary tree. - Example of “enumeration” of the possible moves in the thread game with recursion - Indexing of the board only with [] and slice e.g. A [:, c] selects column c-th. - Drafting of the modular code for enumerating thread moves Homework and Course Conclusion: - From recursive version to how to write an iterative version - Review on Game Trees - Hints to the python argparse module to handle complex input inputs - Brief introduction to Jupyter Notebook
Prerequisites
No requirements.
Books
Allen B. Downey - Thinking in Python (2nd edition)
Frequency
Recommended.
Exam mode
Computer-based exam: development of python code.
Bibliography
Charles Dierbach - Introduction to Computer Science Using Python: A Computational Problem-Solving Focus Python 3 Tutorial - https://docs.python.org/3/tutorial/ Other useful tools: PEP 8 - Style Guide for Python Code - How to write elegant code in python - https://www.python.org/dev/peps/pep-0008/ PEP 257 - Docstring Conventions - Documentation of functions with docstring - https://www.python.org/dev/peps/pep-0257/
Lesson mode
Lectures and computer lab sessions.
  • Lesson code10603314
  • Academic year2024/2025
  • CourseMathematical Sciences for Artificial Intelligence
  • CurriculumSingle curriculum
  • Year1st year
  • Semester1st semester
  • SSDINF/01
  • CFU9
  • Subject areaFormazione informatica