SlideShare une entreprise Scribd logo
1  sur  20
Les structures
répétitives
Jeu de dé
Maintenant on veut afficher le
gagnant après n coups(jets)
(avec n une donnée)
Les taches à faire
• Saisir n qui le nombre de jet ou de coups
Question :
Nouvelle tâche non reconnue :
Comment répéter plusieurs traitement est dont le nombre de
répétition est connu à l’avance ?
Utilisation d’une nouvelle structure qui permet de compter le
nombre de répétition.
La nouvelle structure est : Pour C de VI à VF (pas) faire
Avec
C: est le nom du compteur
VI: valeur initiale
VF : Valeur Finale
Pas :généralement =1
Fonctionnement
Algorithme
Lire (N) // nombre de répétition
Score1 0//c’est mon score
Score2 0//c’est le score d’ordinateur
Pour i de 1à N faire
x1 aléa (1,6)+ aléa(1,6)
x2 aléa(1,6)+ aléa(1,6)
si x1>x2 alors score1score1+1 fin si
si x1<x2 alors score2score2+1 fin si
Fin pour
// affichage du gagnant
Si score1>score2 alors écrire (‘’ j’ai gagné’’)
Sinon si score1<score2 alors écrire(‘’l’ordinateur a
gagné’’)
Sinon écrire (‘’pas de gagnant’’)
Fin si
Fin
Question :
Le nombre de coups à jouer N peut
être négatif ?
Bien sûr que non
Comment obliger l’utilisateur à saisir
une valeur strictement positive?
Ecrire (‘’ donner un entier >0’’)
Lire(N) -6
N
Ecrire (‘’ donner un entier >0’’)
Lire(N) -7
N
Ecrire (‘’ donner un entier >0’’)
Lire(N) 5
On est en train de répéter mais le
nombre de répétition est inconnu et
l’arrêt de la répétition :
dépend d’une condition
C’est quoi cette condition?
l’utilisateur donne une valeur de
n>=1
D’où la nécessite d’utiliser une
nouvelle structure de répétition :
les structures répétitives à condition
Algorithme Python
Répéter ,,jusqu’à (condition) Pas de correspondance
Tant que (condition) faire While (condition) :
Solution
Algorithme Python
Répéter
lire(n)
jusqu’à n>=1
N=int(input(‘’donner un
entier supérieur à 0’’)
While not n>=1:
N=int(input(‘’donner
un entier supérieur à 0’’)
T=False
While T==False:
N=int(input(‘’donner un
entier supérieur à 0’’)
T=n>=1
On désire afficher le gagnant qui dépasse le premier
un score donné et après combien de fois .
Les tâches à faire :
• Saisir un score à atteindre (score>=1)
• Faire le jeu jusqu’à un de
deux joueurs atteint le score donné
• Afficher le gagnant ainsi
après combien de fois
Projet suite
Projet suite
Dans cette partie l’utilisateur ne sait
Combien de fois il va jouer,
Le jeu s’arrête lorsqu’on atteint un
score donné.
Projet suite
Algorithme
Début
//saisie le score à atteindre qui
est normalement un entier >=1
Répéter
lire (score)
Jusqu’à (score >=1)
Sc10
Sc20
K0
Tant que (sc1≠score et sc2≠score ) faire
répéter le jeu
Projet suite
Fonctionnement
Répéter Le ou
les traitement(s )
Condition d’arrêt?
Faux Vrai
Arrêter la
répétition
Fonctionnement
Répéter Le ou
les traitement
Condition?
Faux Vrai
Arrêter la
répétition
Exemple
A 15
B 50
Répéter
R A mod B
AB
BR
jusqu’à B=0
Écrire (A)
Réponse
1- Quand la répétition
s’arrête
Lorsque B sera = 0
2- compléter le
tableauci-dessus
A
B
15
50
R 15
50
15
5
15
5
0
5
0
On arrête car b=0
Exemple
S 0
J1478
Tant que ( J != 0) faire
SS+ j mod 10
JJ div 10
Fin tant que
Ecrire (S)
Réponse
1- Quand la répétition
s’arrête
Lorsque j=0
2- compléter le
tableau ci-dessus
J
S
1478
0
147
8 15
14
19
1
20
0
On arrête car j=0
S il contiendra la valeur 20
QCM

Contenu connexe

Dernier

Cours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdfCours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdf
ssuserc72852
 
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
Faga1939
 

Dernier (13)

gestion des conflits dans les entreprises
gestion des  conflits dans les entreprisesgestion des  conflits dans les entreprises
gestion des conflits dans les entreprises
 
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdfCOURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
COURS SVT 3 EME ANNEE COLLEGE 2EME SEM.pdf
 
Cours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdfCours Préparation à l’ISO 27001 version 2022.pdf
Cours Préparation à l’ISO 27001 version 2022.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
 
Bolero. pptx . Film de A nnne Fontaine
Bolero. pptx . Film   de  A nnne FontaineBolero. pptx . Film   de  A nnne Fontaine
Bolero. pptx . Film de A nnne Fontaine
 
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
L'ÉVOLUTION DE L'ÉDUCATION AU BRÉSIL À TRAVERS L'HISTOIRE ET LES EXIGENCES DE...
 
Boléro. pptx Film français réalisé par une femme.
Boléro.  pptx   Film   français   réalisé  par une  femme.Boléro.  pptx   Film   français   réalisé  par une  femme.
Boléro. pptx Film français réalisé par une femme.
 
Evaluación Alumnos de Ecole Victor Hugo
Evaluación Alumnos de Ecole  Victor HugoEvaluación Alumnos de Ecole  Victor Hugo
Evaluación Alumnos de Ecole Victor Hugo
 
Computer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptxComputer Parts in French - Les parties de l'ordinateur.pptx
Computer Parts in French - Les parties de l'ordinateur.pptx
 
La nouvelle femme . pptx Film français
La   nouvelle   femme  . pptx  Film françaisLa   nouvelle   femme  . pptx  Film français
La nouvelle femme . pptx Film français
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaire
 
Cours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdfCours ofppt du Trade-Marketing-Présentation.pdf
Cours ofppt du Trade-Marketing-Présentation.pdf
 
Sidonie au Japon . pptx Un film français
Sidonie    au   Japon  .  pptx  Un film françaisSidonie    au   Japon  .  pptx  Un film français
Sidonie au Japon . pptx Un film français
 

En vedette

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Les structures répétitives.pptx

  • 2. Jeu de dé Maintenant on veut afficher le gagnant après n coups(jets) (avec n une donnée)
  • 3. Les taches à faire • Saisir n qui le nombre de jet ou de coups Question : Nouvelle tâche non reconnue : Comment répéter plusieurs traitement est dont le nombre de répétition est connu à l’avance ? Utilisation d’une nouvelle structure qui permet de compter le nombre de répétition. La nouvelle structure est : Pour C de VI à VF (pas) faire Avec C: est le nom du compteur VI: valeur initiale VF : Valeur Finale Pas :généralement =1
  • 5. Algorithme Lire (N) // nombre de répétition Score1 0//c’est mon score Score2 0//c’est le score d’ordinateur Pour i de 1à N faire x1 aléa (1,6)+ aléa(1,6) x2 aléa(1,6)+ aléa(1,6) si x1>x2 alors score1score1+1 fin si si x1<x2 alors score2score2+1 fin si Fin pour // affichage du gagnant Si score1>score2 alors écrire (‘’ j’ai gagné’’) Sinon si score1<score2 alors écrire(‘’l’ordinateur a gagné’’) Sinon écrire (‘’pas de gagnant’’) Fin si Fin
  • 6.
  • 7. Question : Le nombre de coups à jouer N peut être négatif ? Bien sûr que non Comment obliger l’utilisateur à saisir une valeur strictement positive?
  • 8. Ecrire (‘’ donner un entier >0’’) Lire(N) -6 N Ecrire (‘’ donner un entier >0’’) Lire(N) -7 N Ecrire (‘’ donner un entier >0’’) Lire(N) 5
  • 9. On est en train de répéter mais le nombre de répétition est inconnu et l’arrêt de la répétition : dépend d’une condition C’est quoi cette condition? l’utilisateur donne une valeur de n>=1 D’où la nécessite d’utiliser une nouvelle structure de répétition : les structures répétitives à condition
  • 10.
  • 11. Algorithme Python Répéter ,,jusqu’à (condition) Pas de correspondance Tant que (condition) faire While (condition) : Solution Algorithme Python Répéter lire(n) jusqu’à n>=1 N=int(input(‘’donner un entier supérieur à 0’’) While not n>=1: N=int(input(‘’donner un entier supérieur à 0’’) T=False While T==False: N=int(input(‘’donner un entier supérieur à 0’’) T=n>=1
  • 12. On désire afficher le gagnant qui dépasse le premier un score donné et après combien de fois . Les tâches à faire : • Saisir un score à atteindre (score>=1) • Faire le jeu jusqu’à un de deux joueurs atteint le score donné • Afficher le gagnant ainsi après combien de fois Projet suite
  • 13. Projet suite Dans cette partie l’utilisateur ne sait Combien de fois il va jouer, Le jeu s’arrête lorsqu’on atteint un score donné.
  • 14. Projet suite Algorithme Début //saisie le score à atteindre qui est normalement un entier >=1 Répéter lire (score) Jusqu’à (score >=1) Sc10 Sc20 K0 Tant que (sc1≠score et sc2≠score ) faire répéter le jeu
  • 16. Fonctionnement Répéter Le ou les traitement(s ) Condition d’arrêt? Faux Vrai Arrêter la répétition
  • 17. Fonctionnement Répéter Le ou les traitement Condition? Faux Vrai Arrêter la répétition
  • 18. Exemple A 15 B 50 Répéter R A mod B AB BR jusqu’à B=0 Écrire (A) Réponse 1- Quand la répétition s’arrête Lorsque B sera = 0 2- compléter le tableauci-dessus A B 15 50 R 15 50 15 5 15 5 0 5 0 On arrête car b=0
  • 19. Exemple S 0 J1478 Tant que ( J != 0) faire SS+ j mod 10 JJ div 10 Fin tant que Ecrire (S) Réponse 1- Quand la répétition s’arrête Lorsque j=0 2- compléter le tableau ci-dessus J S 1478 0 147 8 15 14 19 1 20 0 On arrête car j=0 S il contiendra la valeur 20
  • 20. QCM