Accueil / Contact

Bienvenu sur :

logotop







Site d'initiation à l'algorithmique
LANGAGE PYTHON.
Conforme aux nouveaux programmes du lycée.


ESPACE LIBRE

EXERCICES:LA BOUCLE FOR AVEC PYTHON


LES EXERCICES:


On donne l’algorithme suivant:
En langage naturel
Instructions
Pour i allant de 0 à 10
P ← 5 × i
Afficher i
Afficher P
Fin pour

1.Combien de boucles fait cet algorithme ?
2.Que fait cet algorithme ?
3.Traduire cet algorithme en langage Python.
4.Modifier cet algorithme pour qu’à la sortie il affiche la table de multiplication de 7 (jusqu' à 7 × 25).
En langage naturel
IInstructions
Pour i allant de 1 à 22.
Y = i²
Afficher i
Afficher Y
Fin pour

1.Que fait cet algorithme?
2.Traduire cet algorithme en langage Python.
3.Que faudrait il modifier dans l’algorithme pour qu’à la sortie il n’affiche que le carré de 22 ?
4.Modifier ce programme pour qu’à la sortie il affiche que les carrés d’un nombre impair compris entre 1 et 23.
On donne l’algorithme suivant:
En langage naturel
Initialisation
p ← le train sifflera trois fois
m ←Tchou
Instructions
affiche p
Pour i allant de 1 à 3
Afficher rn
Fin pour
1.De quels types sont les variables p et m ?
2.Que fait cet algorithme ?
3.Traduire l’algorithme précédent en langage Python.
4.Modifier cet algorithme en Python pour que le train siffle 9 fois.
On donne l’algorithme suivant :
En langage naturel
Initialisation
x← l ,5
Instructions

Pour i allant de 1 à 10
x ← x + 1
y ← 3x² +x+1
Afficher y
Fin pour
1.De quel type sont les variable x et y ?
2.Que fait cet algorithme ?
3.Ecrire cet algorithme en Python.
4.Modifier cet algorithme pour que x varie de1à 10 avec un pas de 0,25.
Réponses possibles

Pour accéder aux réponses,Cliquez !

EX1:
Question 1: Il y a 11 boucles.
Question 2: Cet algorithme donne le résultat de la table de multiplication de 5 jusqu'à la multiplication par 10.
Question 3: un programme possible:
En langage Python
# Instruction #
for i in range(11):
   p=5*i
# on utiise la fonction format pour mettre en evidence la table#
   print(" 5 x {} ={} ". format (i,p))

Question 4: un programme possible:
En langage Python
# Instruction #
for i in range(26):
   p=7*i
# on utiise la fonction format #
   print(" 7 x {} ={} ". format (i,p))
EX2: Question 1: Cet algorithme calcule le carré des entiers de 1 à 22.
Question 2:
En langage Python
# Instructions #
for i in range (1,23):
   y=i**2
# on utiise la fonction format #
   print("Le carre de {} est {} ".format (i,y))

Question 3: C'est l'indentation qui va faire la différence.
En langage Python
# Instructions #
for i in range(23):
   y= i**2
# on utiise la fonction format #
print("Le carre de {} est {} ".format (i,y))

Question 4: un programme possible:
En langage Python
# Instructions #
for i in range(12):
   k=2*i+1
   y=k**2
# on utiise la fonction format #
   print("Le carre de {} est {} ".format (k,y))

EX3: Question 1: Les variables sont de type chaîne de caractères(string en anglais)
Question 2: Il va afficher tchou tchou tchou,le siflement du train.
Question 3: un programme possible:
En langage Python
# Initialisation #
p="le train sifflera trois fois "
m="tchou"
# Instructions #
print(p)
for i in range(3):
  print(m)

Question 4: un programme possible:
En langage Python
# Initialisation #
p="le train sifflera 9 fois "
m="tchou"
# Instructions #
print(p)
for i in range(3):
  print(3*m)

EX4:
Question 1: x et y sont de type float (nombres à virgule).
Question 2: cet algorithme calcule la valeur de y lorsque x varie de 2,5 jusqu'à 11,5.
Question 3: un programme possible:
En langage Python
# Initialisation #
x=1.5
# Instructions #
for i in range(10):
   x=x+1
   y=3*x**2+x+1
   print (x,y)

Question 4: un programme possible:
En langage Python
# Initialisation #
x=0.75
# Instructions #
for i in range(37):
   x=x+0.25
   y=3*x**2+x+1
   print(x,y)


					
					
logotop