User Tools

Site Tools


programming:python:python

Hello world !

Exercice 1 : print

  • Open a terminal
  • Create your file by writing the following command
vim ex1.py
  • Enter insertion mode by pressing Insert
  • Write the line below
print("Hello world !")
  • Then press Esc key
  • Save the file
  • Execute
python3 ex1.py

Exercice 2 : input

  • Open a terminal
  • Create your file by writing the following command
vim ex2.py
  • Enter insertion mode by pressing Insert
  • Write the line below
prenom = input('Salut! Quel est ton prénom ?\n')
nom = input('Et ton nom alors ?\n')
 
print("Salut " + prenom + " " + nom)
  • Then press Esc key
  • Save the file
  • Execute
python3 ex2.py

Exercice 3 : for

  • Open a terminal
  • Create your file by writing the following command
vim ex3.py
  • Enter insertion mode by pressing Insert
  • Write the line below
nombre = input('Salut!\nEntre un nombre: ')
 
for i in range(int(nombre)):
    print(i+1, end=' ')
  • Then press Esc key
  • Save the file
  • Execute
python3 ex3.py

Exercice 4 : for2

  • Open a terminal
  • Create your file by writing the following command
vim ex4.py
  • Enter insertion mode by pressing Insert
  • Write the line below
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')
  • Then press Esc key
  • Save the file
  • Execute
python3 ex4.py
programming/python/python.txt · Last modified: 2022/11/30 12:41 by ateixeira