1
0
forked from tdwojak/Python2018
Python2018/labs02/task09.py

35 lines
1.0 KiB
Python
Raw Normal View History

2018-05-12 11:37:19 +02:00
#!/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):
2018-06-02 22:02:05 +02:00
for i in range(len(text)):
if ((text[i]) == 'e'):
text = text[:i] + '3' + text[i + 1:]
elif ((text[i]) == 'l'):
text = text[:i] + '1' + text[i + 1:]
elif ((text[i]) == 'o'):
text = text[:i] + '0' + text[i + 1:]
elif ((text[i]) == 't'):
text = text[:i] + '7' + text[i + 1:]
return text
2018-05-12 11:37:19 +02:00
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))