# braille.py

Created by schraf

Created on August 05, 2020

1.62 KB

Vidéo d’explication

Programme pour apprendre les lettres de l’alphabet Braille (sans les accents)

Dans le menu qui s’affiche, choisir 1 si vous voulez lire des mots écrits en braille (tapez le mot pour vérifier ou simplement touche EXE), choisir 2 pour écrire en braille (touches 1-2-4-5-7-8 du clavier) des lettres de l’alphabet tirées au hasard et 3 pour que la machine écrive en braille le mot que vous taperez.

```from random import *
BRA = [1,5,3,11,9,7,15,13,6,14,17,21,19,27,25,23,31,29,22,30,49,53,46,51,59,57]
MOTS = ["CHIEN","ZEBRE","KIWI","LAPIN","LOUP","LYNX","PONEY","PYTHON","THON","YACK","ZEBU","CHAT","OURS","VACHE","SOURIS","RAT","OIE","ANE","BOA","CERF","COBRA","FAON","HIBOU"]
ALPHA = list(range(65,91))

def aff(m):
v = ["","",""]
for c in m:
code = ord(c) - 65
l = BRA[code] if code>=0 and code<26 else 0
for i in range(6):
v[i//2] += "o" if 1 & (l>>i) else "."
if i%2: v[i//2] += " "
for i in range(3):
print(v[i])

def lire(p):
aff(p)
rep = input("mot ? ").upper()
if rep == p:
print("Bravo !")
return 1
else:
print("Non...", p)
return 0

def ecrire(p):
# ti83 : t = "784512OPTUYZ"
# casio : t = "784512MNPQUV"
t = "784512MNRSWX"
print("Ecrire",chr(p))
rep = input("touches ? ")
s = 0
for c in rep:
try: n = t.index(c)
except:
print("Erreur clavier !")
break
s += 2**(n % 6)
if s == BRA[p - 65]:
print("Bravo !")
return 1
else:
print("Non...")
aff(chr(p))
return 0

print("1. Lire\n2. Ecrire\n3. Mot vers braille\n4. Quitter")
return int(input("Choix ? "))

def melange(l):
return sorted(l,key=lambda x:random())

def go(nb=10):
while True:
if choix == 4: return
if choix == 3:
mot = input("mot ? ")
aff(mot.upper())
else:
if choix == 1:
p, jeu = melange(MOTS), lire
else:
p, jeu = melange(ALPHA), ecrire
sc = 0
for i in range(nb): sc += jeu(p[i])
print("Score =",int(100/nb*sc),"%")

go()```