amélioration code + ajout d'une classe
This commit is contained in:
parent
54ae91d5d1
commit
334d60922a
1 changed files with 42 additions and 20 deletions
|
@ -1,22 +1,44 @@
|
||||||
def wordforphone(mot = None):
|
class Wordtophone:
|
||||||
if not mot:
|
|
||||||
mot = input()
|
def __init__(self):
|
||||||
mot = list(str(mot).lower())
|
self.replace = {
|
||||||
mot2 = []
|
"a": "2",
|
||||||
a = 0
|
"b": "22",
|
||||||
for n in mot:
|
"c": "222",
|
||||||
a += 1
|
"d": "3",
|
||||||
if n != " ":
|
"e": "33",
|
||||||
n = n.replace("a","2").replace("b","22").replace("c","222").replace("d","3").replace("e","33").replace("f","333").replace("g","4").replace("h","44")
|
"f": "333",
|
||||||
n = n.replace("i","444").replace("j","5").replace("k","55").replace("l","555").replace("m","6").replace("n","66").replace("o","666").replace("p","7")
|
"g": "4",
|
||||||
n = n.replace("q","77").replace("r","777").replace("s","7777").replace("t","8").replace("u","88").replace("v","888").replace("w","9").replace("x","99")
|
"h": "44",
|
||||||
n = n.replace("y","999").replace("z","9999")
|
"i": "444",
|
||||||
mot2.append(n)
|
"j": "5",
|
||||||
if a < len(mot):
|
"k": "55",
|
||||||
mot2.append(" - ")
|
"l": "555",
|
||||||
mot2 = str(mot2).replace("[","").replace("]","").replace("'","").replace(",","").replace(" "," ")
|
"m": "6",
|
||||||
print(mot2)
|
"n": "66",
|
||||||
input("PRESS ENTER TO EXIT")
|
"o": "666",
|
||||||
|
"p": "7",
|
||||||
|
"q": "77",
|
||||||
|
"r": "777",
|
||||||
|
"s": "7777",
|
||||||
|
"t": "8",
|
||||||
|
"u": "88",
|
||||||
|
"v": "888",
|
||||||
|
"w": "9",
|
||||||
|
"x": "99",
|
||||||
|
"y": "999",
|
||||||
|
"z": "9999",
|
||||||
|
" ": " -"
|
||||||
|
}
|
||||||
|
|
||||||
|
def wordforphone(self, mot = None):
|
||||||
|
if not mot:
|
||||||
|
mot = input()
|
||||||
|
mot = str(mot).lower()
|
||||||
|
|
||||||
|
for key in self.replace:
|
||||||
|
mot = mot.replace(key, f"{self.replace[key]} ")
|
||||||
|
return print(mot)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
wordforphone()
|
Wordtophone().wordforphone()
|
||||||
|
|
Reference in a new issue