Cours 06 - Exercices Python

Objectifs

Déroulement

Présentation Introduction à Python

À télécharger: reseaux_pres06.pptx
Vidéo de la présentation

Exemples de scripts Python

exemples.zip

Script 1: Utilisation de boucle

p = int(input("Enter a small number: "))
g = int(input("Enter a large number: "))

if p<g:
    for e in range(p, g+1):
        print(e)
else:
    print("p (" + str(p) + ") needs to be smaller than g (" + str(g) +").")

Script 2: Utilisation de liste

p = int(input("Enter a small number: "))
g = int(input("Enter a large number: "))

myList = []

if p<g:
    for e in range(p, g+1):
        myList.append(e)
else:
    print("p (" + str(p) + ") needs to be smaller than g (" + str(g) +").")

print(str(len(myList)))
print(myList)