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

35 lines
867 B
Python
Raw Normal View History

2017-11-18 16:45:28 +01: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):
2017-12-01 18:12:26 +01:00
replacements = ( ('e','3'), ('l','1'),
('o','0'), ('o','7') )
my_string = text
new_string = my_string
for old, new in replacements:
new_string = new_string.replace(old, new)
return new_string
2017-11-18 16:45:28 +01:00
pass
2017-12-01 18:12:26 +01:00
2017-11-18 16:45:28 +01: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))