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

39 lines
950 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-11-26 22:35:41 +01:00
text_tmp = text
2017-11-26 14:08:10 +01:00
lista_temp = ""
for i in text_tmp:
2017-11-25 16:19:19 +01:00
if i =='e':
2017-11-26 14:54:06 +01:00
lista_temp += '3'
2017-11-25 16:19:19 +01:00
elif i =='l':
2017-11-26 14:54:06 +01:00
lista_temp += '1'
2017-11-25 16:19:19 +01:00
elif i =='o':
2017-11-26 14:54:06 +01:00
lista_temp += '0'
2017-11-25 16:19:19 +01:00
elif i =='t':
2017-11-26 14:54:06 +01:00
lista_temp +='7'
2017-11-25 16:19:19 +01:00
else:
2017-11-26 14:54:06 +01:00
lista_temp +=i
2017-11-25 16:19:19 +01:00
return lista_temp
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))