Repeat alphabets in Python

How do you ensure that a word taken in through a function repeats each of its alphabets in the output.


def word("Hello") should return HHeelllloo

def word("Hi-Tech") should return HHii--TTeecchh


This should do the trick.

def word(txt):
    new_txt = ""
    for letter in txt:
        new_txt += letter*2

    return new_txt

Basically, for every letter, you add 2 of the letter (letter*2) to a string, which you return at the end.

Leave a Reply

Your email address will not be published. Required fields are marked *