Pas de vérification, on suppose que l'utilisateur sait ce qu'il fait.
#! /usr/bin/env python
# 2009/01/08 - mastermind-0.py
# Jeu de Mastermind, premier jet
# Jean Karim Bockstael - jkb@jkbockstael.be
from random import randint
print """Code de 4 chiffres, entre 0 et 9 inclus, a trouver en 5 essais max.
o : bon chiffre, bonne place
x : bon chiffre, mauvaise place
_ : mauvais chiffre
"""
code = ''
for i in range(0,4):
code = code + str(randint(0,9))
trycode = ''
trynum = 0
while trynum < 5:
trynum = trynum + 1
trycode = raw_input('Essai: ')
hint = ''
for i in range(0,4):
if trycode[i] == code[i]:
hint = hint + 'o'
elif code.find(trycode[i]) != -1:
hint = hint + 'x'
else:
hint = hint + '_'
if hint == 'oooo':
break
print trycode, ':', hint
if hint == 'oooo':
print "Gagne!"
else:
print "Perdu! Le code etait:", code
2 comments:
Salut mec :) Si ça te botte, je l'ai fait en C pour l'école :p
Si tu veux le code ;)
Héhé, je me trompe ou on en a parlé un soir à l'Atelier, de ton Mastermind en C ?
De toute façon oui, je suis preneur, y'a mon mail dans la side-Babar.
Enregistrer un commentaire