Solution 1

def chars_in_even_positions(a_string):
    return a_string[1::2]

Solution 2

def chars_in_even_positions(a_string):
    result = ""
    position = 1
    for char in a_string:
        if position % 2 == 0:
            result += char
        position += 1

    return result

Characters in even positions

Write a function chars_in_even_positions that receives a string and returns all the characters in even positions. Example:

chars_in_even_positions('Marvelous')  # avlu
chars_in_even_positions('Python')  # yhn

Test Cases

test with odd length - Run Test

def test_with_odd_length():
    assert chars_in_even_positions('Respect') == 'epc'

test two characters - Run Test

def test_two_characters():
    assert chars_in_even_positions('No') == 'o'

test one characters - Run Test

def test_one_characters():
    assert chars_in_even_positions('X') == ''

test with even length - Run Test

def test_with_even_length():
    assert chars_in_even_positions('Python') == 'yhn'
def chars_in_even_positions(a_string): pass