Allora ragazzi, questo è il mio primo programma che creo. Non ha un utilità , più che altro l'ho fatto per esecizio, ma ci tenevo a farvelo guardare.
Consigli da darmi? Sapete dirmi qualche modo per accorciare il codice?
Codice:
#Questo e' un traduttore in binario by FireSkull
def TraduzioneI_B(parola):
Indice = 0
while Indice < len(parola):
Lettera = parola[Indice]
for Caretteri in parola[Indice]:
if parola[Indice] == 'A':
print "1000001",'\t', " = ",'\t'," A "
elif parola[Indice] == 'B':
print "1000010",'\t', " = ",'\t'," B "
elif parola[Indice] == 'C':
print "1000011",'\t', " = ",'\t'," C "
elif parola[Indice] == 'D':
print "1000100",'\t', " = ",'\t'," D "
elif parola[Indice] == 'E':
print "1000101",'\t', " = ",'\t'," E "
elif parola[Indice] == 'F':
print "1000110",'\t', " = ",'\t'," F "
elif parola[Indice] == 'G':
print "1000111",'\t', " = ",'\t'," G "
elif parola[Indice] == 'H':
print "1001000",'\t', " = ",'\t'," H "
elif parola[Indice] == 'I':
print "1001001",'\t', " = ",'\t'," I "
elif parola[Indice] == 'J':
print "1001010",'\t', " = ",'\t'," J "
elif parola[Indice] == 'K':
print "1001011",'\t', " = ",'\t'," K "
elif parola[Indice] == 'L':
print "1001100",'\t', " = ",'\t'," L "
elif parola[Indice] == 'M':
print "1001101",'\t', " = ",'\t'," M "
elif parola[Indice] == 'N':
print "1001110",'\t', " = ",'\t'," N "
elif parola[Indice] == 'O':
print "1001111",'\t', " = ",'\t'," O "
elif parola[Indice] == 'P':
print "1010000",'\t', " = ",'\t'," P "
elif parola[Indice] == 'Q':
print "1010001",'\t', " = ",'\t'," Q "
elif parola[Indice] == 'R':
print "1010010",'\t', " = ",'\t'," R "
elif parola[Indice] == 'S':
print "1010011",'\t', " = ",'\t'," S "
elif parola[Indice] == 'T':
print "1010100",'\t', " = ",'\t'," T "
elif parola[Indice] == 'U':
print "1010101",'\t', " = ",'\t'," U "
elif parola[Indice] == 'V':
print "1010110",'\t', " = ",'\t'," V "
elif parola[Indice] == 'W':
print "1010111",'\t', " = ",'\t'," W "
elif parola[Indice] == 'X':
print "1011000",'\t', " = ",'\t'," X "
elif parola[Indice] == 'Y':
print "1011001",'\t', " = ",'\t'," Y "
elif parola[Indice] == 'Z':
print "1011010",'\t', " = ",'\t'," Z "
elif parola[Indice] == 'a':
print "1100001",'\t', " = ",'\t'," a "
elif parola[Indice] == 'b':
print "1100010",'\t', " = ",'\t'," b "
elif parola[Indice] == 'c':
print "1100011",'\t', " = ",'\t'," c "
elif parola[Indice] == 'd':
print "1100100",'\t', " = ",'\t'," d "
elif parola[Indice] == 'e':
print "1100101",'\t', " = ",'\t'," e "
elif parola[Indice] == 'f':
print "1100110",'\t', " = ",'\t'," f "
elif parola[Indice] == 'g':
print "1100111",'\t', " = ",'\t'," g "
elif parola[Indice] == 'h':
print "1101000",'\t', " = ",'\t'," h "
elif parola[Indice] == 'i':
print "1101001",'\t', " = ",'\t'," i "
elif parola[Indice] == 'j':
print "1101010",'\t', " = ",'\t'," j "
elif parola[Indice] == 'k':
print "1101011",'\t', " = ",'\t'," k "
elif parola[Indice] == 'l':
print "1101100",'\t', " = ",'\t'," l "
elif parola[Indice] == 'm':
print "1101101",'\t', " = ",'\t'," m "
elif parola[Indice] == 'n':
print "1101110",'\t', " = ",'\t'," n "
elif parola[Indice] == 'o':
print "1101111",'\t', " = ",'\t'," o "
elif parola[Indice] == 'p':
print "1110000",'\t', " = ",'\t'," p "
elif parola[Indice] == 'q':
print "1110001",'\t', " = ",'\t'," q "
elif parola[Indice] == 'r':
print "1110010",'\t', " = ",'\t'," r "
elif parola[Indice] == 's':
print "1110011",'\t', " = ",'\t'," s "
elif parola[Indice] == 't':
print "1110100",'\t', " = ",'\t'," t "
elif parola[Indice] == 'u':
print "1110101",'\t', " = ",'\t'," u "
elif parola[Indice] == 'v':
print "1110110",'\t', " = ",'\t'," v "
elif parola[Indice] == 'w':
print "1110111",'\t', " = ",'\t'," w "
elif parola[Indice] == 'x':
print "1111000",'\t', " = ",'\t'," x "
elif parola[Indice] == 'y':
print "1111001",'\t', " = ",'\t'," y "
elif parola[Indice] == 'z':
print "1111010",'\t', " = ",'\t'," z "
Indice = Indice + 1
n = 0
print "------ Traduttore Italiano-Binario ------"
print "Indice:",'\n'," Premi 0 per usare il traduttore.",'\n' " Premi 1 per uscire dal programma."
n = int(raw_input("Opzione : "))
while n != 1:
if n == 0:
parola = raw_input("Inserisci la parola da tradurre:")
TraduzioneI_B(parola)
n = int(raw_input("Opzione : "))
elif n >= 1:
print "Il programma e' chiuso."
elif n <= -1:
print "Il programma e' chiuso."