Programming lab, log of the lectures
Lecture 24 Offline lecture (recovery)
Read and write json files:
https://drive.google.com/file/d/1zYY_0FKsusB0aF8D0woNxN4G59su3awn/view?usp=sharing
Exercises with json files:
NOTE: the json module will not be an argument of the exam.
Lecture 23 23/12/2020 (recovery)
Exam simulation! Zip of the exam folder:
esercitazione-23-12-2020.zip (solutions:
program.sol.py)
Lecture 22 18/12/2020
Exercise done in class:
https://drive.google.com/file/d/1oeXrg9CNCBJSS1ZaBWZK4tz-Kxgynh_Y/view?usp=sharing
Code seen in class:
prog_lab_lect22.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1pNRTA8fFHqBd6t7FRbAtMeQ1nzPX6ZtP/view?usp=sharing Chat-transcript-20201218-090858_Programming_lab.txt
Lecture 21 16/12/2020
Exercises about recursion, trees and filesystem. Examples:
66.zip 12.zip
Code seen in class:
prog_lab_lect21.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1_4Dg9bBl00wZ0RgBfBV1R93xTFbFU8MZ/view?usp=sharing Chat-transcript-20201216-124127_Programming_Lab.txt
Lecture 20 11/12/2020
Exercises on recursion, recursion limits. Filesystem trees (directory trees). The os module and the os.path module to access the functionalities of the Operating System.
Code seen in class:
prog_lab_lect20.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1lj4cn7oX-N3BDYN0onYfufboE0vzASfJ/view?usp=sharing Chat-transcript-20201211-093625_Programming_Lab.txt
Lecture 19 09/12/2020
Homework 8. Binary trees. N-ary trees.
Code seen in class:
prog_lab_lect19.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/11lPMsvIKCqWJHQ-MyLEItjeoWCIyK9pw/view?usp=sharing Chat-transcript-20201209-124222_Programming_Lab.txt
Lecture 18 04/12/2020
Binary trees.
Code seen in class:
prog_lab_lect18.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1khGav7kS_wNvceWZ21AZ3qjslLNo32tt/view?usp=sharing Chat-transcript-20201204-091149_Programming_lab.txt
Additional exercises
- Write a recursive function that receives a string and a letter as input and counts how many times the letter is repeated in the string, without using string methods.
- Write a recursive function that receives a string as input and returns a pair in which the first value is the number of vowels and the second value is the number of consonants present in the string.
- Write a recursive function that receives two integers as input and returns their product using only additions and subtractions.
- Write a recursive function that receives an integer as input and returns True if the number is prime, False, otherwise.
- Write a recursive function that receives a list of integers and returns the minimum value among all the values in the list.
- Write a recursive function that receives a list of integers and returns a new list in which only the positive values of the original list are present.
- Write a recursive function that takes a binary tree as input and returns the minimum value among all the values of the nodes of the tree.
- Write a recursive function that takes a binary tree as input and returns the minimum value among all the values of the tree leaves.
- Write a recursive function that takes a binary tree as input and prints the values of all leaves from the right to the left.
- Write a recursive function that takes a binary tree and a level L as input, and returns the sum of the values in the nodes to the L level.
Lecture 17 02/12/2020
Exercises about recursion.
Code seen in class:
prog_lab_lect17.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/10vKlTmddJh39PDgPBudAH8wAqtGVZ_vc/view?usp=sharing Chat-transcript-20201202-124026_Programming_lab.txt
Lecture 16 27/11/2020
Exercises on images.
Try debugging our class code:
turtle.py.txt (remember to rename it in .py)
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1R4spLdpAjhwm60mS3M_Wbx97Zye0s1NF/view?usp=sharing Chat-transcript-20201127-091451_Programming_lab.txt
Json example files:
https://jsonplaceholder.typicode.com/posts https://jsonplaceholder.typicode.com/users https://jsonplaceholder.typicode.com/comments
Lecture 15 25/11/2020
Example images:
Discussions about HW6-req. Exercises on images, with recursive and iterative solutions.
Code seen in class:
prog_lab_lect15.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1Px82mwsbQb6iVnnDja2YCzjHj1uoKsDq/view?usp=sharing Chat-transcript-GMT20201125-124010_Programming_lab.txt
Lecture 14 20/11/2020
Classes and images.
Code seen in class:Prog_lab_lect14.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/16GCmZjnMxz_NbPlbkJtkdhUZvvqXPhN8/view?usp=sharing Chat-transcript-20201120-091312_Programming_lab.txt
Lecture 13 18/11/2020
Classes and images.
Code seen in class:
Prog_lab_lect13.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1v64pZR0Sqix6Tija0NgaJtA-2oXZdJp-/view?usp=sharing Chat-transcript-20201118-124113_Programming_lab.txt
Lecture 12 13/11/2020
Classes. Example: Point and Rectangle classes. Matrices.
Code seen in class:
Prog_lab_lect12.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1jqws-hqrrHAxYp1R85qdD0No05ZPqcn4/view?usp=sharing Chat-transcript-20201113-092109_Programmin_lab.txt
Lecture 11 11/11/2020
Classes. Example: Point class.
Code seen in class:
Prog_lab_lect11.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1jdS4kaeizD0cEvuaWOZjE0Udgchwphjk/view?usp=sharing Chat-transcript-20201111-124710_Programming_lab.txt
Additional exercise
Complete the Rectangle class with the required methods.
Lecture 10 6/11/2020
Introduction to HW4-req. Solution of the additional exercise of lecture 9.
Code seen in class:
Prog_lab_lect10.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1g-Hpe6jVazGuEjpT9e0uI9bfVacYFuaK/view?usp=sharing Chat-transcript-20201106-091602_Programming_lab.txt
Lecture 9 4/11/2020
Understanding the key parameter for the sorting functions. Reading and writing text files.
Code seen in class (examples and exercises):
Prog_lab_lect09.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1yOkpQNocvRf03M4CNyH3mpiYz7zehyfZ/view?usp=sharing Chat-transcript-20201104-123542_Programming_lab.txt
Additional exercise
Write a function that reads the four files in the books.zip file and evaluates the relative frequency of the 26 letters, ignoring the distinction between lower and capital letters. The result has to be a dictionary of dictionaries: for each letter there should be a dictionary associated in which there are the filenames of the books as keys and the relative frequency of the letter for each book.
The relative frequency of a letter in a book can be evaluated as the ratio between the occurrences of that letter and the total number of letters in the book.
Lecture 8 30/10/2020
Homework assignment 3 (optional). Reading and writing text files.
Code seen in class (examples and exercises):
Prog_lab_lect08.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1OZY37ENpM0SXCaG2guHKBjBCKvSlCdmz/view?usp=sharing Chat-transcript-20201030-091035_Programming_lab.txt
Additional exercises
- Write a function that takes as an input a string containing a series of words separated by spaces and builds a dictionary where the keys are the last letters of the words in the string and the associated values are lists with the words ending with that letter. The lists must be ordered lexicographically.
For example, for the string "the only impossible journey is the one you never begin" must return {'e':['the', 'impossible', 'the', 'one'], 'y':['only', 'journey'], 's':['is'], 'u':['you'], 'r':['never'], 'n':['begin']}.
- Write a function that takes as an input a dictionary in which each key is a string and the value is an integer and returns the ordered list of all keys with a even value.
For example, {'mickey mouse':12, 'pluto':3, 'minnie':7, 'goofy':4, 'donald duck':3 } -> ['mickey mouse','goofy'].
- Write a function that takes as an input a dictionary of the type {key:integer list} and returns a new dictionary with the same keys but as a value the average of the integers in the original dictionary list.
- Write a function that takes as input two key:list dictionaries and returns a new dictionary with the keys present in both input dictionaries and with values the list given by the merging of the two input lists, associated with the same key.
- Write a function that takes as an input a string of words separated by spaces and builds a dictionary where the keys are the word lengths and the values are sets with the words that have exactly that length in numbers of characters.
Lecture 7 28/10/2020
Dictionaries, strings and sets.
Code seen in class (examples and exercises):
Prog_lab_lect07.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1G1s9xWXM9Zz9ydtxpfzvcSX2KFtOONNz/view?usp=sharing
Lecture 6 23/10/2020
Cyclomatic complexity (aka intricacy), past homework solution (see classroom exercise zip), deleting elements from a list while visiting the list.
Classroom exercise (solutions in Prog_lab_lect06.zip file):
classroom_ex06.zip
Code seen in class (examples and exercise solutions):
Prog_lab_lect06.zip
- past_hw1_1.py: solution where for each grade we count how many students are admitted
- past_hw1_2.py: solution where for each grade we sum 1 for the threshold <= than grade
- past_hw1_3.py: solution where for exploit that students admitted for threshold t will be admitted also for any threshold < t
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1yepMH4y8RsBX3RMiBqokQvWhje39U0W1/view?usp=sharing
Lecture 5 21/10/2020
Timeit magic, string and list methods, map function, random, for vs while, recursion.
Code seen in class (examples and exercises):
Prog_lab_lect05.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1Td7fJ4AwKr1b-TXgZSqPrLTSDcmzWgGu/view?usp=sharing
Lecture 4 16/10/2020
For statement, operations on strings, lists, operations on lists. Homework assignment 1.
Code seen in class (examples and exercises):
programming_lab_4.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1gGZYCXK4d9JftcX3_fF5U2nIkWI1rEKm/view?usp=sharing
Additional exercises
For exercises with lists, if possible, write both the WITH and WITHOUT "range" version.
- Write a function that gets three integers as an input d, m, a (it is assumed that a is always an odd number to avoid leap years) and returns True or False depending on whether the three numbers form a valid date in the "d/m/a" format. Ex: 30/2/2017 False, 1/1/1111 True.
- Write a function that gets a list of integers as an input and returns the sum of all even numbers minus the sum of all odd numbers.
- Write a function that gets as an input a string of words separated by spaces and returns a list with the lengths of words in the string.
- Write a function that checks if a list is sorted in ascending order (<=) (let's suppose that the list contains sortable objects) and, in case, returns True, False otherwise.
Lecture 3 14/10/2020
Comparison operators, if and for statements, lists.
Code seen in class (examples and exercises):
Prog_lab_lect03.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1COb6LzKCzUfRJboUbxEzpFZ_MwkA0EAA/view?usp=sharing
Lecture 2 9/10/2020
Variable, names, integers, floats, strings, functions. Some exercises.
Code seen in class (examples and exercises):
Prog_lab_lect02.zip
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1oZzVo71_P5aJ3sUHRecyvACYw9t05P0v/view?usp=sharing
Lecture 1 7/10/2020
Course introduction, computer science to solve problems with computing, terminal and GUI (Graphical User Interface), raw text files and binary files, binary and hexadecimal numeric representation, ASCII and UTF-8 encoding, python interpreter and IDLE, arithmetic expressions, difference between interactive mode and script mode.
Lecture recording (only accessible to registered students):
https://drive.google.com/file/d/1QvnYhQEHP0IKnft5KricZXu8LFYwDxwY/view?usp=sharing
Additional exercises
- Write a python script that takes in input a float number, calculates its cube root and prints it on screen
- Write a python script that takes a person name (name) and the name of a fruit (fruit) and prints: "(name) loves to eat (fruit)".
- Write a python script that takes in input two floats a and b and calculates and prints c, corresponding to the hypotenuse of the rectangle triangle having for cathets two sides of length a and b, respectively
- Write a python script that takes in input three floats a, b, c, and calculates and prints the expression:
- Write a python script that takes three floats a, b, c, and calculates and prints the two x roots of the equation:
Lecture 0: getting started.
Getting started guide.
--
Angelo Spognardi - 2020-09-28
Comments
*