1
0
forked from tdwojak/Python2017
Python2017/labs02/task09.py
2017-11-19 15:44:36 +01:00

38 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):
text = text.lower()
text = text.replace('o', '0')
text = text.replace('l', '1')
text = text.replace('z', '2')
text = text.replace('e', '3')
text = text.replace('h', '4')
text = text.replace('s', '5')
text = text.replace('g', '6')
text = text.replace('t', '7')
text = text.replace('b', '8')
return text
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))