1
0
forked from tdwojak/Python2017
Python2017/labs02/task10.py
2017-11-27 21:23:07 +01:00

77 lines
1.8 KiB
Python

#!/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'.
"""
#tekst=("edyta")
#def pokemon_speak(tekst):
#for litera in tekst:
#if litera in tekst[::2]:
#return litera.upper()
#def pokemon_speak(text):
#return [text.upper() for x in text[::2]]
#def pokemon_speak(text):
#return [x.upper() for x in text[::2]]
#if litera in text[::2]:
#return text[::2].upper()
#else:
#return text[::1].lower()
#pokemon_speak("edytarenkjacek")
def pokemon_speak(text):
indices=set([0,2,4,6,8,10,12,14,16,18])
#indices=set(index(text[::2]))
return("".join(c.upper() if i in indices else c for i, c in enumerate(text)))
# def fold(s):
# uppers = s[0::2].upper()
# lowers = s[1::2].lower()
# return zip(uppers, lowers)
# def fold(s):
# time_to_upper = True
# result = ""
# for ch in s:
# if time_to_upper:
# result += ch.upper()
# else:
# result += ch.lower()
# time_to_upper = not time_to_upper
# return result
#
# def fold(s):
# time_to_upper = True
# result = ""
# for ch in s:
# if time_to_upper:
# result += ch.upper()
# else:
# result += ch.lower()
# time_to_upper = not time_to_upper
# return result
#
# s="edyta"
#indices=set([text[::2]])
def tests(f):
inputs = [['pokemon'], ['do not want'], ['POKEMON']]
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__":
print(tests(pokemon_speak))