User Tools

Site Tools


programming:python:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
programming:python:python [2022/11/30 10:17] – created ateixeiraprogramming:python:python [2022/11/30 12:41] (current) ateixeira
Line 1: Line 1:
 ====== Hello world ! ====== ====== Hello world ! ======
-===== Exercice 1 : printf =====+===== Exercice 1 : print =====
  
   * Open a terminal   * Open a terminal
Line 21: Line 21:
 </code> </code>
  
 +===== Exercice 2 : input =====
 +
 +  * Open a terminal
 +  * Create your file by writing the following command
 +<code python>
 +vim ex2.py
 +</code>
 +  * Enter insertion mode by pressing Insert
 +  * Write the line below
 +<code python>
 +
 +prenom = input('Salut! Quel est ton prénom ?\n')
 +nom = input('Et ton nom alors ?\n')
 +
 +print("Salut " + prenom + " " + nom)
 +
 +</code>
 +  * Then press Esc key
 +  * Save the file
 +  * Execute 
 +<code>
 +python3 ex2.py
 +</code>
 +
 +===== Exercice 3 : for =====
 +
 +  * Open a terminal
 +  * Create your file by writing the following command
 +<code python>
 +vim ex3.py
 +</code>
 +  * Enter insertion mode by pressing Insert
 +  * Write the line below
 +<code python>
 +
 +nombre = input('Salut!\nEntre un nombre: ')
 +
 +for i in range(int(nombre)):
 +    print(i+1, end=' ')
 +</code>
 +  * Then press Esc key
 +  * Save the file
 +  * Execute 
 +<code>
 +python3 ex3.py
 +</code>
 +
 +===== Exercice 4 : for2 =====
 +
 +  * Open a terminal
 +  * Create your file by writing the following command
 +<code python>
 +vim ex4.py
 +</code>
 +  * Enter insertion mode by pressing Insert
 +  * Write the line below
 +<code python>
 +
 +nombre1 = input('Salut!\nEntre un premier nombre\n')
 +nombre2 = input('Et un deuxième nombre: ')
 +
 +for i in range(int(nombre1), int(nombre2) - int(1), -1)):
 +    print(i, end='\n')
 +
 +</code>
 +  * Then press Esc key
 +  * Save the file
 +  * Execute 
 +<code>
 +python3 ex4.py
 +</code>
programming/python/python.1669803439.txt.gz · Last modified: 2022/11/30 10:17 by ateixeira