ajout fichiers projets en python
This commit is contained in:
10
projets/README.md
Normal file
10
projets/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
## Projets
|
||||
|
||||
Ici nous listerons les groupes et projets en cours de travail
|
||||
|
||||
|
||||
|
||||
Projets vu en classe:
|
||||
|
||||
- [Mastermind](mastermind.py)
|
||||
- [Pendu](pendu.py)
|
||||
39
projets/mastermind.py
Normal file
39
projets/mastermind.py
Normal file
@@ -0,0 +1,39 @@
|
||||
mport random
|
||||
|
||||
code = [] # code établi par l'ordinateur
|
||||
pCode = [] # code rentré par l'utilisateur
|
||||
pCode_s = "" #texte rentré par le joueur
|
||||
cInCode = 0 # couleur présente dans le code
|
||||
cInPlace = 0 # bonne couleur à la bonne place
|
||||
essais = 12 #nombre d'essais disponibles
|
||||
essai = 1 #essai actuel
|
||||
|
||||
while len(code) <4:
|
||||
code.append(random.choice(['J','B','R','V','O','N']))
|
||||
|
||||
gameOver = False
|
||||
while gameOver == False:
|
||||
print("essai", essai, "sur 12")
|
||||
pCode_s = str(input("Entrez une combinaison de couleurs(un espace entre chaque) \n"))
|
||||
pCode = pCode_s.split(' ')
|
||||
|
||||
i = 0
|
||||
while i < len(code):
|
||||
if pCode[i] == code[i]:
|
||||
cInPlace +=1
|
||||
i+=1
|
||||
i = 0
|
||||
while i < len(pCode):
|
||||
cInCode += code.count(pCode[i])
|
||||
i+=1
|
||||
|
||||
essai +=1
|
||||
print(cInPlace, " pions de bonne couleur à la bonne place")
|
||||
print(cInCode, " pions de bonne couleur")
|
||||
if cInPlace == 4 or essai == essais:
|
||||
gameOver = True
|
||||
print("Vous avez gagné !")
|
||||
print("code :", ('').join(code))
|
||||
cInCode = 0
|
||||
cInPlace = 0
|
||||
quit()
|
||||
50
projets/pendu.py
Normal file
50
projets/pendu.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import random
|
||||
choix = ["toto", "nsi", "patate", "jeanclaude"]
|
||||
solution = random.choice(choix)
|
||||
|
||||
essais = 7
|
||||
affichage = ""
|
||||
lettres_trouvees = ""
|
||||
|
||||
for l in solution:
|
||||
affichage = affichage + "_ "
|
||||
|
||||
print(">> Bienvenue dans le pendu <<")
|
||||
|
||||
while essais > 0:
|
||||
print("\nMot à deviner : ", affichage)
|
||||
proposition = input("proposez une lettre : ")[0:1].lower()
|
||||
|
||||
if proposition in solution:
|
||||
lettres_trouvees = lettres_trouvees + proposition
|
||||
print("-> Bien vu!")
|
||||
else:
|
||||
essais = essais - 1
|
||||
print("-> Nope\n")
|
||||
if essais==0:
|
||||
print(" ==========Y= ")
|
||||
if essais<=1:
|
||||
print(" ||/ | ")
|
||||
if essais<=2:
|
||||
print(" || 0 ")
|
||||
if essais<=3:
|
||||
print(" || /|\ ")
|
||||
if essais<=4:
|
||||
print(" || /| ")
|
||||
if essais<=5:
|
||||
print("/|| ")
|
||||
if essais<=6:
|
||||
print("==============\n")
|
||||
|
||||
affichage = ""
|
||||
for x in solution:
|
||||
if x in lettres_trouvees:
|
||||
affichage += x + " "
|
||||
else:
|
||||
affichage += "_ "
|
||||
|
||||
if "_" not in affichage:
|
||||
print(">>> Gagné! <<<")
|
||||
break
|
||||
|
||||
print("\n * Fin de la partie * ")
|
||||
Reference in New Issue
Block a user