Browsing articles from "novembre, 2010"

TP5 : Correction

Exercice 5.1 – Structures de boucle


  • >>> i = 1
    >>> while (i<=50) :
    ... print(i)
    ... i += 1
    ...

  • >>> i = 0
    >>> while (i <= 10) :
    ... print(i, 'x 9 =', i*9)
    ... i += 1
    ...

  • >>> i = 65
    >>> while (i <= 90) :
    ... print(chr(i), end=' ')
    ... i += 1
    ...


  • >>> i = 5
    >>> j = 10
    >>> while (i > 0) :
    ... k = j
    ... while (k > 0) :
    ... print('*', end='')
    ... k -= 1
    ... j -= 2
    ... i -= 1
    ... print()
    ...

Exercice 5.2 – Fonctions


  • def ligne(n) :
    "Affichage d'une ligne de n étoiles"
    while (n > 0) :
    print('*', end='')
    n -= 1
    print()

    i = 5
    j = 10
    while (i > 0) :
    ligne(j)
    j -= 2
    i -= 1

  • def factorielle(n) :
    if (n == 0) :
    return 1
    else :
    r = 1
    while (n > 0) :
    r *= n
    n -= 1
    return r

    print(10, '! = ', factorielle(10))
    print(1, '! = ', factorielle(1))
    print(0, '! = ', factorielle(0))

  • def maximum(x, y, z) :
    r = x
    if (r < y) :
    r = y
    if (r < z) :
    r = z
    return r

    print(maximum(5, 3, 4))

Exercice 5.3 – Retour en enfance avec la tortue


  • from turtle import *

    def carre(c) :
    i = 1
    while (i<=4) :
    forward(c)
    left(90)
    i += 1

    carre(100)
    input()


  • from turtle import *

    def triangle(c) :
    i = 1
    while (i<=3) :
    forward(c)
    left(120)
    i += 1

    i = 1
    while (i <= 6) :
    triangle(100)
    left(60)
    i += 1
    input()

TP4 : Correction


Fatal error: Class 'GeSHi' not found in /homez.47/infodev/www/wp-content/plugins/codecolorer/codecolorer-core.php on line 155