cours_progra/bac1/q1/renforcement/renforcement_2510/ex3.py
Debucquoy 4fd7542f03
.
2023-09-20 15:18:20 +02:00

44 lines
976 B
Python

def find_max_count(in_list):
max_count = 0
for i in in_list:
count = 0
for j in in_list:
if j == i:
count += 1
if max_count < count:
el = i
max_count = count
return el
def ask_word():
word = input('input your encrypted word separated with space ' ' : ')
return word.split()
def new_alphabet(translation):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
ret = alphabet[translation:] + alphabet[:translation]
return ret
def decode(to_decode):
"""decode en trouvant le e qui est la chaine de character la plus presente
:to_decode: TODO
:returns: TODO
"""
max_char = int(find_max_count(to_decode))
decalage = 5 - max_char
language = new_alphabet(decalage)
decoded = [language[int(i) - 1] for i in to_decode]
return decoded
if __name__ == "__main__":
letters = ask_word()
d = decode(letters)
[print(i, end='') for i in d]