I don't understand, wy function counting do not take result rotate function?
maybe someone give me a hint?
def counting(cipher_grille, ciphered_password):
global result
result = ""
index_word = 0
for word in cipher_grille:
index_element = 0
for element in word:
if element == "X":
result += ciphered_password[index_word][index_element]
index_element += 1
index_word += 1
return result
def rotate(cipher_grille):
list_cipher_grille = []
list_cipher_grille = ','.join(cipher_grille)
str1, str2, str3, str4 = list_cipher_grille.split(",")
cipher_grille = zip(str4, str3, str2, str1)
return cipher_grille
def recall_password(cipher_grille, ciphered_password):
all_result = ""
counting(cipher_grille, ciphered_password)
all_result += result
rotate(cipher_grille)
counting(cipher_grille, ciphered_password)
all_result += result
rotate(cipher_grille)
counting(cipher_grille, ciphered_password)
all_result += result
rotate(cipher_grille)
counting(cipher_grille, ciphered_password)
all_result += result
return all_result
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert recall_password(
('X...',
'..X.',
'X..X',
'....'),
('itdf',
'gdce',
'aton',
'qrdi')) == 'icantforgetiddqd', 'First example'
assert recall_password(
('....',
'X..X',
'.X..',
'...X'),
('xhwc',
'rsqx',
'xqzz',
'fyzr')) == 'rxqrwsfzxqxzhczy', 'Second example'
And second question, how i can that code block more shorter and more pretty? I try simple *4 in the end, but give more errors.
counting(cipher_grille, ciphered_password)
all_result += result
rotate(cipher_grille)
counting(cipher_grille, ciphered_password)
all_result += result
rotate(cipher_grille)
counting(cipher_grille, ciphered_password)
all_result += result
rotate(cipher_grille)
counting(cipher_grille, ciphered_password)
all_result += result
Created at: 2019/06/10 10:45; Updated at: 2019/06/11 04:50
The question is resolved.