Home > front end >  How can I extend a word with a loop with Python3?
How can I extend a word with a loop with Python3?

Time:09-07

I'm a beginner and I'm working on an assignment where I want Python to use user input and extend the word.

If user input is monkey the output (print) should be: m-oo-nnn-kkkk-eeeee-yyyyyy

This is my start but it only outputs: m-o-n-k-e-y

Do you have any hints on how I can go forth? https://codeshare.io/8p6nB4

    inp = input("Give me a word to extend: ")
    index = -len(inp)
    ext_inp = ''
    for letter in inp:
        if index < 0:
            ext_inp  = inp[index]   '-'
            index  = 1
        print(ext_inp)

CodePudding user response:

word_to_be_extended = input("give me a word to extern:")
word_after_extend = ''
for i in range(len(word_to_be_extended)):
    word_after_extend  = word_to_be_extended[i] * (i 1)
    if i != len(word_to_be_extended)-1:
        word_after_extend  = '-'
print(word_after_extend)
  • Related