Python is a very versatile programming language and can especially be used for scientific programming and image processing. Python’s syntax is very similar to Matlab’s one. Before beginning this lab, you may need to read Paragraph.
First, boot your computer on Ubuntu, then open Jupyter Lab or VSCodium.
Using Jupyter Lab
Jupyter Lab runs in a web browser.
Open a terminal by typing
terminalin the main menu or typing Ctrl + Alt + T.Start Jupyter by typing in a terminal:
jupyter labor
jupyter-lab
Using VSCodium
Open the main menu and type
VSCodiumto start the sotware.
Now you are ready to write a Python program in the notebook.
In the first cell of the notebook, write
40 + 2and type
Shift+Return. The code is executed, the result is displayed then a new cell appears below.Like any programming language, the code is written using variables and functions. A variable stores one (or more) values, whether it is numeric or not. The name of the variable can contain letters, numbers (except the first character) or underscore. Case is important (i.e.
aandAare two different variables). Type the instructions below in the second cell:year = 2026 course = "BIP"and type again Shift + Return. Now the value 2026 is stored in the variable
yearand the character string “BIP” is stored in the variablecourse.Modify the previous cell by adding the following statement:
print(f"{course} {year}")printis a function and the string in the brackets is an argument. Here, this argument is a character string. Thefat the beginning of the string means that it is a formatted string. Type Shift + Return to run again the code.
A notebook is appealing as it is also possible to add text using the markdown language.
Select an empty cell, then click on the drop-down list in the toolbar to select Markdown. Then you can write formatted text. Try to write:
New exercise¶
Write bold, italic or equations: .
This can be useful for inserting titles or keeping comments and notes.
Verify your code in the correction below.
Correction¶
Objectives¶
Discover and know how to write a Python program.
Discover and know how to use a notebook.
Write by using the markdown syntax.
Manipulate variables.
Code cells¶
The two cells containing codes should be:
40 + 242year = 2026
course = "BIP"
print(f"{course} {year}")BIP 2026
Markdown cell¶
The markdown cell should be:
## New exercise
Write **bold**, *italic* or equations: $\sqrt{2}$.to get:
New exercise¶
Write bold, italic or equations: .