-3

Question is:

PAPER DOLL: Given a string, return a string where for every character in the original there are three characters:

paper_doll('Hello') --> 'HHHeeellllllooo'
paper_doll('Mississippi') --> 'MMMiiissssssiiippppppiii'

and I wrote the code:

def paper_doll(text):
    for lettes in text:
        for i in range(0, len(text) - 1):
            return text[i] * 3
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
vikash
  • 27
  • 5
  • This may help https://stackoverflow.com/questions/38273353/how-to-repeat-individual-characters-in-strings-in-python – tan_an Jul 09 '20 at 10:42

3 Answers3

0

Use this code, this function will take every letter from the given text, triple it and return the new string :

def paper_doll(text):
    out = []
    for letter in text:
        out.append(letter*3)
    return ''.join(out)
Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
-1

You have a few mistakes in your script

One is your for loop is outside of the definition, Second is you don't call your function.

def paper_doll(text):
for lettes in text:
    for i in range(0,len(text)-1):
        return text[i]*3

Try this one:

text="hello"
newtext2=""

def paper_doll(text,newtext2):

    for letter in text:
        newtext = str( letter* 3)
        newtext2+=newtext

    print(newtext2)


paper_doll(text,newtext2)
-2

there are a few reasons why your code won't work as you intend to:

  1. you are returning the output instead of printing it
  2. your code is running through an extra loop which is unnecessary

this would do the job:

def paper_doll(text):
    for letter in text:
        print(letter * 3, end="")
Vishal Singh
  • 6,014
  • 2
  • 17
  • 33