Reputation: 85
using python how can i get an out out to look like this dooggg so each letter it repeats once more. i have tried something that looks like this
# Program 21
def double(source):
pile = ""
for letter in source:
pile = pile+letter+letter
print pile
print pile
but it comes out looking like
dd
ddoo
ddoogg
Upvotes: 1
Views: 49
Reputation: 3459
Try...
def double(source):
word = []
for x in range(len(source)):
word.append(source[x]*(x+1))
print ''.join(map(str, word))
double("dog")
input()
and if you want it all on one line try this for python 2:
def double(source):
word = []
for x in range(len(source)):
word.append(source[x]*(x+1))
print ''.join(map(str, word)),
double("dog")
input()
and this for python 3:
def double(source):
word = []
for x in range(len(source)):
word.append(source[x]*(x+1))
print(''.join(map(str, word)), end="")
double("dog")
input()
Upvotes: 1
Reputation: 113988
"".join(l*i for i,l in enumerate(my_word,1))
I think should do it
Upvotes: 1