forked from tdwojak/Python2018
41 lines
967 B
Python
41 lines
967 B
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):
|
|
text2=[]
|
|
for znak in text:
|
|
if znak == 'e':
|
|
text2.append('3')
|
|
elif znak == 'l':
|
|
text2.append('1')
|
|
elif znak == 'o':
|
|
text2.append('0')
|
|
elif znak == 't':
|
|
text2.append('7')
|
|
else:
|
|
text2.append(znak)
|
|
text2 = ''.join(text2)
|
|
return text2
|
|
|
|
|
|
|
|
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))
|