1
0
forked from tdwojak/Python2017
Python2017/labs02/task09.py
2017-11-26 14:08:10 +01:00

42 lines
1.1 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Napisz funkcję leet_speak, która podmienia w podanym napisie niektóre litery
na podobnie wyglądające cyfry: 'e' na '3', 'l' na '1', 'o' na '0', 't' na '7'.
Np. leet('leet') powinno zwrócić '1337'.
"""
def leet_speak(text):
text_tmp = str(text)
text_tmp = text_tmp.replace('[', '')
text_tmp = text_tmp.replace(']', '')
text_tmp = text_tmp.replace("'", '')
lista_temp = ""
for i in text_tmp:
if i =='e':
lista_temp.append('3')
elif i =='l':
lista_temp.append('1')
elif i =='o':
lista_temp.append('0')
elif i =='t':
lista_temp.append('7')
else:
lista_temp.append(i)
return lista_temp
def tests(f):
inputs = [['leet'], ['do not want']]
outputs = ['1337', 'd0 n07 wan7']
for input, output in zip(inputs, outputs):
if f(*input) != output:
return "ERROR: {}!={}".format(f(*input), output)
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(leet_speak))