Computer Code Python CCP 06 : importation de modules

lgsp(40)
Published in
#fr
Words
192
Reading
1 min
8y
Listen to this post
~1 min

Table of Contents

  1. Importation du module random
  2. Importation du module math
  3. Importation du module sys
  4. Bilan
  5. Pour aller plus loin

Importation du module random

import random
for i in range(20):
    print(random.randint(1, 10))

from random import *
for i in range(20):
    print(randint(1, 10))

Importation du module math

import math 
phi = (1 + math.sqrt(5)) / 2
print(phi)
print(math.pi)

from math import *
phi = (1 + sqrt(5)) / 2
print(phi)
print(pi)

Importation du module sys

import sys
while True:
    print('Taper "exit" pour sortir.')
    reponse = input()
    if reponse == 'exit':
    sys.exit()
    print('Vous avez tapé ' + reponse + '.')

from sys import *
while True:
    print('Taper "exit" pour sortir.')
    reponse = input()
    if reponse == 'exit':
    exit()
    print('Vous avez tapé ' + reponse + '.')    

Bilan

Dans ce cours nous avons vu :

  • 3 exemples de modules random, math et sys
  • 2 façons pour importer un module

Pour aller plus loin

Computer Code Python CCP 06 : importation de modules | Ecency