User Tools

Site Tools


programming:python:python

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programming:python:python [2022/11/30 10:30] ateixeiraprogramming:python:python [2022/11/30 12:41] (current) ateixeira
Line 45: Line 45:
 </code> </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.1669804232.txt.gz · Last modified: 2022/11/30 10:30 by ateixeira