Semaine 4, jour 2
This commit is contained in:
34
Semaine_04/Exercices/pendu.py
Normal file
34
Semaine_04/Exercices/pendu.py
Normal file
@@ -0,0 +1,34 @@
|
||||
word_to_find = "parapluie"
|
||||
word_hidden = "_" * len(word_to_find)
|
||||
list_word_hidden = list(word_hidden)
|
||||
attempts = 10
|
||||
|
||||
already_chosen_letter = []
|
||||
|
||||
print(word_hidden)
|
||||
|
||||
while word_hidden != word_to_find and attempts > 0:
|
||||
chosen_letter = input("Saisir une lettre > ").strip().lower()[0] # on ne prend VRAIMENT que la première lettre
|
||||
|
||||
if chosen_letter in already_chosen_letter:
|
||||
print(f"Vous avez déjà saisie la lettre {chosen_letter.upper()}.")
|
||||
attempts -= 1
|
||||
continue
|
||||
|
||||
already_chosen_letter.append(chosen_letter)
|
||||
|
||||
if chosen_letter not in word_to_find:
|
||||
attempts -= 1
|
||||
continue
|
||||
|
||||
for index, letter in enumerate(word_to_find):
|
||||
if letter == chosen_letter:
|
||||
list_word_hidden[index] = chosen_letter
|
||||
|
||||
word_hidden = "".join(list_word_hidden)
|
||||
print(f"Il reste {attempts} tentatives. \n {word_hidden} \n")
|
||||
|
||||
if word_hidden != word_to_find:
|
||||
print(f"Perdu ! Le mot était {word_to_find.upper()}.")
|
||||
else:
|
||||
print("Gagné !")
|
||||
Reference in New Issue
Block a user