1
0
Fork 0
Python2017/labs02/task10.py

31 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ę pokemon_speak, która zamienia w podanym napisie co drugą literę
na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
"""
def pokemon_speak(text):
2017-11-28 19:38:07 +01:00
pokemon_text=[]
for i in range(len(text)):
if i%2==0 and ord(text[i])>=97 and ord(text[i])<=122:
pokemon_text.append(str(chr(ord(text[i])-32)))
else:
pokemon_text.append((text[i]))
return "".join(pokemon_text)
2017-11-18 16:45:28 +01:00
def tests(f):
2017-11-28 19:38:07 +01:00
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
2017-11-18 16:45:28 +01:00
outputs = ['PoKeMoN', 'Do nOt wAnT', 'POKEMON']
for input, output in zip(inputs, outputs):
if f(*input) != output:
return "ERROR: {}!={}".format(f(*input), output)
break
return "TESTS PASSED"
if __name__ == "__main__":
2017-11-28 19:38:07 +01:00
print(tests(pokemon_speak))