szabgab / wis-python-course-2024-04

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WIS Python programming course started in 2024.04

course

Students

Home page Repo Assignments Project Status
Adam Liberman repo solutions
Adi Bar-El Meisel repo
Ana Mejia Fleisacher repo solutions
Avital Rosner repo solutions project
Boaz Yaari repo solutions
Boyue Sun repo solutions
Chen Davidyan Krisi repo solutions
Daniella Dayagi repo
Ekaterina Zhigileva repo solutions
Elad Wizman repo
Hadar Klimovski repo solutions
Hernan Rubinstein repo solutions
Liron Hoffman repo solutions
Maher Salhab repo solutions
Mazal Faraj repo solutions
Meir Sylman repo solutions
Noy Ravensary repo solutions
Omer Sapir repo solutions
Omer Zachar repo solutions
Orlena Benamozig repo
Peleg Schneider repo
Rebecca Bornstein repo solutions
Roi Siegelman repo solutions
Sameeha Mittwali repo
Shahar Garin repo solutions
Shaked Levy repo solutions
Thay Karmin repo solutions
Thea Meimoun repo solutions
Yael Arieli repo solutions project
Yuval Bernard repo solutions

Plan

Schedule

  • Day 1 2024.04.11 9:00-12:00
  • Day 2 2024.04.18 9:00-12:00
  • 2024.04.25 Pesach
  • Day 3 2024.05.02 9:00-12:00
  • Day 4 2024.05.09 9:00-12:00
  • Day 5 2024.05.16 9:00-12:00
  • Day 6 2024.05.23 9:00-12:00
  • Day 7 2024.05.30 9:00-12:00
  • 2024.06.06 9:00-12:00
  • 2024.06.13 9:00-12:00
  • 2024.06.20 9:00-12:00

Participation in the lectures

There is no requirement to participate in the lectures. You will be able to watch the videos later. However, it is recommended to participate as that gives you an opportunity to ask questions.

Timestamps

Each video will be around 1 hour long. In order to make it easier to access the specific topics I would like to add timestamps to each video. A timestamp looks like this:

00:00 Start
01:30 Installation

Meaning at 1 minute 30 seconds I started to talk about Installation.

I'll need volunteers to prepare these timestamps for each video on the day after the lecture. You basically need to watch the video and write down all the points where you think you or someone else would like to jump to. You can see such timestamps in the comments of many YouTube videos. We will have an issue where you'll be able to volunteer.

Assignments

There will be assignments after every lecture. You will submit them via GitHub. I'll explain the details during the lectures.

Project

Towards the end of the course you'll be asked to do a project. First you need to submit a proposal for the project and when it is accepted then implement it. The project should be something that is useful for your studies or at least it is fun for you to make. Ask in the lab where you work what needs are there that you might implement as your final project. You can get inspiration from the projects listed here and the projects of the 2023 autumn semester.

Grades

  • Each assignment counts as 5% (we will have 10 of them).

  • The project proposal is 15%.

  • The project is 35%.

  • The project is a requirement. Without that you won't get a passing grade.

Slides

During the course I'll use some of the slides that can be found here. These slides are publicly available and will remain on the web site after the course is over.

Videos in English

There are recording of this course from 3 years ago.

There are also recordings from the 2023 autumn semester.

You can watch those, but be also warned, this semester the order of the material will be different.

There are many more videos in my English-language YouTube channel. You are invited to check them out and to follow the channel.

Videos in Hebrew

Some of the material is also available in Hebrew. You can find them on my website and in my Hebrew-language YouTube channel. You are invited to follow that channel as well.

Language

The standard language of WIS and of this course is English.

However, when on one-on-one conversions I'd be happy to speak in Hebrew, Hungarian, Spanish, or Ladino.

Installations

There is no need to install anything up front. We'll do that during the lectures.

Day 1

Videos

  • Day 1 part 1 - About GitHub and programming

    • 03:24 course overview: assignments, project, etc.
    • 11:25 version control systems: Git and GitHub
    • 14:24 change history
    • 19:58 python: open-source programming language
    • 25:35 python extensions: libraries, BioPython, pypi.org
    • 28:29 issues
    • 35:00 pull requests
    • 40:40 GitHub pages
  • Day 1 part 2 - GitHub pages via the GitHub UI

    • 00:13 Building a website and account
    • 07:24 Create new repository
    • 09:55 Actions tab
    • 11:17 Opening the website
    • 12:15 Editing the website through README.md
    • 15:30 md file format and editing
    • 18:10 Observing commits
    • 19:50 View page source
    • 20:50 Adding links and figures
    • 24:44 Creating a new page
    • 27:40 Create a link to the new page
    • 30:40 Designing the website via _config.yml
    • 32:47 Static Site Generators (SSG) and Jekyll
    • 38:05 Upload file and add it to the page
    • 45:00 Use your GitHub Pages website
    • 46:50 embed uploaded picture
    • 50:45 Create new folder and upload picture
    • 53:30 Delete file
  • Day 1 part 3 - Installing git on Windows, Setup, simple use; Installing VS Code

    • 06:25 - installing Git
    • 13:15 - open Git on your computer
    • 18:42 - cloning a repository to your local disk using SSH keys
    • 27:23 - working on your repository on your local disk: add a new file
    • 30:34 - downloading VS code editor
    • 33:32 - edit files in vs code and commit them locally with Git
    • 41:54 - Git push: publish your local commits to GitHub
    • 45:08 - assignment explanation
    • 49:01 - questions

Notes

git config --global user.email your@mail.address.com
git config --global user.name "Your Name"

Git commands:

git clone ...
git status
git add
git commit -m "some explanation"
git push
  • Generate ssh private key and add it to your GitHub Account.
ssh-keygen                 (just press ENTER several times accepting all the defaults)
cat ~/.ssh/....pub
  • (git) bash commands
pwd               print working directory
cd  /c/Users      change directory

In the File Explorer click on "view" and then mark the check-boxes: "File name extensions" and "Hidden items"

Assignment (day 1)

  • Create your own GitHub

  • Create you own web site on GitHub pages

  • Open an issue on our shared GitHub project with the link to that site and to the repository.

  • Dead-line 2024.04.15 24:00

Day 2

Videos

  • Day 2 part 1 - Installing VS Code and Python on Windows

    • 00:00 - Review previous assignment
    • 03:49 - Following and staring a GitHub repository
    • 10:10 - Editors for running Python
    • 16:00 - Installing VS Code
    • 18:04 - Opening a folder/file on VS Code
    • 28:25 - Creating a Python file
    • 32:04 - Running a Python program
    • 36:17 - Installing Python
    • 42:06 - Printing Hello world
    • 43:37 - Questions
  • Day 2 part 2 - Getting input from STDIN

    • 01:05 - git diff
    • 01:24 - git commit
    • 02:21 - git push
    • 05:40 - git pull
    • 11:40 - Python variables
    • 17:12 - strings in double quotes
    • 20:11 - embedding variables in f-strings
    • 20:20 - format
    • 21:19 - comments
    • 28:44 - input
    • 31:19 - Add two numbers together
    • 38:13 - int
    • 40:11 - float
  • Day 2 part 3 - flow control: if, while, and break

    • 00:00 - git mv
    • 06:28 - if condition and else
    • 08:33 - Check for equality ==
    • 09:28 - indentation
    • 18:30 - lower()
    • 21:54 - capitalize
    • 24:30 - built-in method, parentheses ()
    • 29:57 - while
    • 34:05 - break
    • 34:40 - Ctrl-C
    • 35:28 - How to avoid the break (actualy the earlier solution using break is better)
    • 41:15 - DRY
    • 45:00 - random
    • 45:50 - docs.python.org
    • 50:30 - random.random random.randrange
    • 56:40 why did you use git mv ?
  • Review assignment

  • How to follow a GitHub repository

  • Star a GitHub repository

  • VS Code

    • Ctrl-P to open a file
    • highlight and press Ctrl-/ to comment out several rows
  • Install Python.

  • Start writing Python code in VS Code.

    • Hello World day02/hello_world.py
    • Welcome someone using input.
    • Add two numbers together
    • Multiply numbers
    • int()
    • float()
    • if statement, indentation, else ==, !=
    • while, break
    • DRY
  • Keep the repository up to date.

git diff
git mv

Assignment (day 2)

  • On your "home page" (the one you created last week)

    • Link to the lab in Weizmann where you are in your rotation or where you do your research. Link to your workplace if you are not at Weizmann.
    • Link to the home page of some of the other students in the course.
    • Add a picture of you or an avatar to your GitHub account and also to your homepage.
    • Add a page with some notes about this course and links to the repository.
    • Link to the repository where you are going to publish your solutions.
  • Setup notifications and "star" the repository.

  • Create a new public repository where you are going to publish all of your assignments. (It should be different from your homepage).

  • Write a Python program that is a number guessing game:

    • The computer "thinks" a about a whole number between 1 and 20
    • The user guesses
    • The computer tells if the guess was too small, too big or exact.
    • If exact the user wins, the program ends. Otherwise the user can guess again.
    • At the end of the game print out how many guesses the user needed.
  • In your assignment repository create a folder called "day02" and put your submitted solution there.

  • Open an issue on our project with a link to the repository where you have the solution.

  • Dead-line 2024.04.30 24:00

Day 3

  • Day 3 part 1 - Git, code-formatting, random.py

    • 00:05 Repository cloning.

    • 03:52 Several ways of creating github repositories and connecting them to github

    • 04:50 How to clone empty repository

    • 07:25 Opening visual studio code from bash commend

    • 13:50 additional git commands

    • 16:53 GitHub Actions errors of the GitHub Pages of Mazal

    • 29:00 Code formatting importance

    • 31:00 Install and use black for code formatting: (beautifier, prettifyer, code formatter)

    • 34:00 Opening terminal from visual studio code

    • 35:40 Example of how to use black

    • 40:50 Create program called random.py and have it also import random.

    • Some students needed help.

    • The GitHub Actions errors of the GitHub Pages of Mazal.

    • Install and use black for code formatting:( beautifier, prettifyer, code formatter)

    • Create program called random.py and have it also import random.

  • Day 3 part 2

    • 00:01 Discuss the __pycache__ folder.
    • 08:16 Show .gitignore
    • 30:40 The solutions of Rebecca has a file called .DS_Store.
    • 34:14 The solutions of Ana has the __pycache__ folder. First remove with git rm and then add the name to .gitignore.
    • 36:05 functions in python
  • Day 3 part 3

    • 01:07 write a function that given a string of digits, and count how many times each digits appear.

    • 04:08 how and in which order python read the function

    • 06:25 using a list and counting digits in python

    • 11:15 how to access a specific element from a list

    • 13:00 go back to counting digits

    • 31:10 separate the display function

    • 33:37 how to skip spaces from counting

    • Take the rectangle example and convert into 4 functions, including the main function.

    • Count digits

    • write a function that given a string of digits, count how many times each digit appears; (use a list)

    • define a list and access its elements

    • add spaces to the string and skip them in counting.

    • add other characters to the string and skip them in counting.

Assignment (day 3)

  • Visit the home pages of some of the students. Pick two students you don't know yet and who don't have issues opened yet.

    • Open an issue on their assignment repository. (I think issues are not enabled on the repository use for the GitHub pages, so we need to open the issue in the assignments repository.)
    • Praise the parts you like in the web site.
    • Suggest an improvement to the web site or suggest a topic to cover on the web site more in depth. (e.g. Adam likes traveling, so ask for a few more pictures, or a favorite location.)
    • In the issue mention me using @szabgab so I'll be notified.
  • When you receive such an issue, please react to it. Once you finished implementing whatever it suggested (if there was anything), then close it.

  • Create a folder called "day03". Take the solution from the previous assignment, the number guessing game, copy it to the new "day03" folder and make some changes

    • Allow the user to play several games: once one game ends ask her if she wants to play again, generate a new random number and play again.
    • If the user enters "x" any time, exit the program.
    • If the user enters "n" any time, leave the current game and ask if she wants to play a new game?
    • If the user enters "s" any time, show the hidden number (cheating).
    • Move the code in a function called main and split up the code into several function that make sense.
  • Dead-line 2024.05.08 16:00

Day 4

  • Day 4 part 1 -

    • 02:00 About comments in the code
    • 04:20 Example of unnecessary comments
    • 07:00 Following up on committed comments: git blame & git show
    • 16:22 Commit using source control in visual studio
    • 22:30 Explain what is recursion
    • 23:30 Recursion example: factorial function
    • 31:30 sys library & sys.argv
    • 46:30 Code efficiency: input() vs sys.argv()
    • 56:50 stop condition in recursion functions
    • Show the problem (e.g. factorial(1000))
    • Discuss the problem with recursive calling main - in the number guessing game it is better to have two while loops.
  • Day 4 part 2

    • 03:00 - Example of factorial in a non-recursive way.
    • 10:50 - Fibonacci example.
    • 23:15 - Read a string from a file to count the digits
    • 30:23 - Explain about open file.
    • 36:35 - Explain about read options.
    • Read a string from a file to count the digits
    • sys.argv
    • with, open, read
  • Day 4 part 3

    • 00:25 count all the characters from the file
    • 03:40 using dictionary
    • 09:40 displaying a content of dictionary
    • 18:30 counting characters line by line
    • 25:55 using .rstrip()
    • 28:30 spyder and jupyter notebook
    • 34:00 debugger
    • Count letters, count words
    • Spyder
    • Jupyter Notebook

Factorial

n!  f(n) = n*(n-1)*(n-2) .... 1

f(1) = 1
f(n) = n * f(n-1)

Fibonacci

 1, 1, 2, 3, 5, 8, 13, ...
f(1) = 1
f(2) = 1
f(n) = f(n-1) + f(n-2)

Do not comment unnecessarily:

exit()  # end the program

An example when comments go bad:

counter = 0


counter += 2 # add 1 to the counter

Comment where things are unclear:

score = (round(100 * (1 - ((n - 1) / 19)) * (1 / (1 + (0.004 * t)))))

Explain "why" not the "what"

Assignment (day 4)

Create a folder called day04 and write a program that given a filename on the command line will print the following:

  • How many characters does the file have.
  • How many lines are in the file.
  • How many words are in the file. (For our purpose you can assume that any two things separated by spaces are separate words.)
python count.py FILENAME
  • Dead-line 2024.05.15 22:00

Day 5

  • Day 5 part 1 - TIMESTAMP MISSING
    • 00:38 - comments about code
    • 04:30 - Memory (RAM)
    • 13:30 - CPU
    • 20:00 - GPU
    • 24:30 - how to create modules and import them
    • 40:00 - student question- python extension
    • 46:00 - displaying the different methods for importing modules
    • about computers (hard-disk, memory, CPU (cores), GPU)
    • using modules, import
  • Day 5 part 2 - TIMESTAMP MISSING
    • 00:00 - Introduction to code quality assurance.
    • 10:30 - Intentional bug in custom library; writing a testing program to check for bugs.
    • 12:25 - pytest package: installation and using pytest.assert.
    • 18:40 - Interpreting a test report.
    • 19:50 - Student question: correctly using the pytest package.
    • 22:55 - Student discussion: multiple pytest.assert calls in a single testing function.
    • 29:30 - Asserting multiple cases in conjunction with @pytest.mark.parametrize
    • 37:50 - Running a specific test within a whole testing program.
    • 39:57 - Further motivation for writing tests for code.
    • pip install pytest
  • Day 5 part 3 - TIMESTAMP MISSING

Take the Fibonacci function and move to a module. Write tests.

area function with a bug

pytest --doctest-modules mymath.py

Assignment (day 5)

Create a folder called day05 copy your solution from day 4 (character, word, and line counting)

  • Change it to have separate function(s) that do the "business logic".

  • Move that to a separate "library" file.

  • Write tests for these functions. (Some people had one function some had several. Either way is fine.)

  • Dead-line 2024.05.21 22:00

Day 6

  • Day 6 part 1 - TIMESTAMP MISSING

    • Exception handling
  • Day 6 part 2

    • 01:02 - Exception handling
    • 11:55 - Introduction to specific file handling
    • 18:14 - YAML files
    • 24:42 - JSON files
    • 26:03 - INI files
    • 26:25 - TOML files
    • 27:00 - YAML library reading example
    • 33:16 - CSV Library reading example
    • 40:07 - next()
    • 44:03 - DictReader()
  • Day 6 part 3

    • 00:00 - start
    • 01:53 - pillow (python imaging library) library
    • 04:47 - Image.open
    • 06:03 - format, size, mode
    • 15:35 - resize
    • 18:05 - other image actions with pillow
    • 20:11 - draw_triangle
    • 27:00 - read spreadsheets
    • 28:10 - openpyxl (create and edit spreadsheet file)
    • 39:35 - worksheet title
    • 40:35 - expressions
    • 42:20 - create chart (graph) in excel)
    • 42:45 - read_excel
    • 44:35 - closing
    • Read image using pillow
    • Read Excel file
  • Slides of Python and Excel

  • Slides of YAML

  • Exception hierarchy

Assignment (day 6)

Create a folder called day6 and in it:

Find an important Excel or CSV file in the lab where you work and write a program that will do some computation on it. Include a sample of the data file and write a test that will verify the results given that input file.

If you don't work in any lab, ask the other participants of the course for a file. Worst case you can download a file from Kaggle.

If the files you have contain data that you don't want to be public, replace the real data with fake values.

I know that "some computation" is rather vague, but that's because in each case something els might make sense.

Calculation might be summing up certain numbers or maybe doing a slightly more complex calculation on the data. Maybe collecing and listing some values that might be numerical or textual.

Please also add a README.md to the day6 folder explaining in a few words or few sentences what the data is and what kind of computation you do.

  • Dead-line 2024.06.02 22:00

Day 7

  • Day 7 part 1
    • 00:00 Start
    • 00:46 issues from assignments
    • 11:05 requirements file
    • 16:27 pip freeze
    • 19:48 pipeline
    • 20:50 grep
    • 23:30 deprecationWarning
    • 36:21 path problem
    • 42:07 name == "main":
  • Day 7 part 2
    • 00:00 - name == "main"
    • 07:25 - path problem
    • 09:07 - .gitignore
    • 10:28 - unittest
    • 15:42 - output plots in tests
    • 18:54 - tkinter
    • 21:15 - testing in temporary folders
    • 28:40 - Final project
    • 42:00 - Importing data from web (Scientific Python)
  • Day 7 part 3 - TIMESTAMP MISSING

Create virtual environment:

virtualenv -p python3 venv

Start virtual envrionment:

source venv/bin/activate

On Windows it is probably started by running .\venv\bin\activate.bat

pip install pytest
pip install -r requirements.txt
$ pip freeze
et-xmlfile==1.1.0
iniconfig==2.0.0
openpyxl==3.1.3
packaging==24.0
pluggy==1.5.0
pytest==8.2.1
  • Discuss the warnings in day6 project of Yael - Show the way Roi hides them

  • Introduce the requirements.txt file (see the project of Yuval)

  • Boyue - show the problem with the hard-coded path

  • The problem with having code in the body of the program Meir

  • Review the code of Maher (unittest, __name__, hard-coded filename)

  • Roi - test generates an image should be either in gitignore or better yet in a temporary folder

  • Testing using the file (Shahar)

  • Talk about the project, set date for project proposals

  • Getting data from web sites Open Weathermap API

  • Scientific Python

  • BioPython

Assignment (day 7)

Create day07 folder

Write a command line tool that can download data from NCBI. You can download from the nucleotide database as we did in the lecture, but it would be much more interesting if you used some of the other databases available on NCBI. e.g.:

python ncbi.py  TERM NUMBER

Search for the TERM and download up to NUMBER items.Save each item in its own file. Print the names of the files. Also save the date, the search term, the number asked for and the total number of items found in a csv file. So if you run it twice

python ncbi.py  Orchid 3
python ncbi.py  cauliflower 7

you'd get something like this:

date,term,max,total
2024-05-30 17:20:21,Orchid,3,527341
2024-05-30 18:12:34,cauliflower,7,32781

Add a README.md that explain what the program does.

  • Dead-line 2024.06.09 22:00

Project proposal

As I explained in the lecture you will have to write a project that is hopefully going to be useful or fun for you.

Size: about 4 times bigger than a weekly assignment.

Create a new git repository and in the README.md file describe the project. Add links to explanations and images if necessary. This is the project proposal and this will also become the user-documentation.

The proposal should include the scientific background of the project and the technical, programming part.

The scientific part will likely include many terms I am not familiar with. Please include links to explanations. This part should also include the explain about the models and how the data is processed. If you use well-known algorithms then please link to explanations.

The technical part is mostly "standard", but it is better to be explicit about it. So:

  • How to install the dependencies? That should be: pip install -r requirements.txt.
  • How to run the tests that come with the program? People should be able to just run pytest and that should run the tests.
  • What kind of input does the program expect and how to run the program. e.g.:
    • The program will receive the name of the input CSV files on the command line and will print the results to the screen: python project.py input-1.csv input-2.csv.
    • The program will open a window with windows to fill in the input parameters. (this can be implemented using Tkinter)

If your project relies on some data (most likely it will), then include some data files in the repository. The actual values in the file can be fake, but the format of the file should be the same as the file(s) you already have.

Please give the project a real title that is meaningful to other researchers and not just "project", after all these projects are expected to have value way beyond being projects for this course. Name the repository accordingly.

It would be nice if the README had a reference to the course e.g. a link back to our repo something like this,

This project was originally implemented as part of the Python programming course at the Weizmann Institute of Science taught by Gabor Szabo

but beyond that it is just a stand-alone project.

Open an issue on our repository with a link to this repo.

  • Dead-line 2024.06.16 22:00

Day 8

pip install jupyter
jupyter lab
jupyter notebook
  • Day 8 part 3 - TIMESTAMP MISSING
    • Jupyter notebook examples
    • image manipulation

Assignment (day 8)

One of the following two in the day08 folder:

  1. Take the number guessing game and create GUI for it using Tk.

    • Have a button or a menu option to exit the game.
    • Have a button to restart the game - the computer generates a new random number and resets the guess-counter.
    • Have a button that will show the currently hidden value in a pop-out dialog.
  2. Create a GUI for the ncbi.py of the previous assignment.

    • Have a box to type in the search term.
    • Another box to type in the number - how many to download.
    • A selector to select the database. (nucleotide, ...?)
    • A selector to select the file-format (GeneBank, FASTA, what else can be there?).
    • A button to "download the data".
  • Include a README.md in the day08 folder.
  • Include a requrements.txt if necessary.

I'd strongly recommend that before you submit the solution to me, show it to one of the other students and let that person try it.

  • Dead-line 2024.06.16 22:00

About


Languages

Language:Python 84.2%Language:Jupyter Notebook 15.8%