1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import string
import random
liste = ['Alain', 'Antoine', 'Bernard', 'Colin', 'Christine', 'François', 'Guy', 'Gérard', 'Léa', 'Léon', 'Louis', 'Nathalie', 'Serge', 'Sylvie', 'Sylvain', 'Vincent']
listeNoms = []
def lettre_au_hasard():
lettre = random.choice(string.ascii_uppercase)
return (lettre)
def rechercherNoms(liste, lettre):
for i in range (len(liste)):
mot = liste[i]
iteration = list(mot)
for i in range (0,1):
if (iteration[i] == lettre):
listeNoms.append(mot)
if (len(listeNoms) == 0):
return ('La liste ne contient aucun élément commencant par '+ lettre)
else :
return (listeNoms)
#Main
lettre = (lettre_au_hasard())
print ('La lettre générée aléatoirement est : ' + lettre)
print (rechercherNoms(liste, lettre)) |
Partager