-3

I am trying to write a code that returns a user input as the following example-

User input:- hello

Return: H-Ee-Lll-Llll-Ooooo

Basically, I want each letter increased by 1, a dash between each letter, and the first letter being capital between each dash.

Thanks!

2 Answers2

1

If you can control that the input will always be lowercase, the answer from @Sup is smaller.

In case you need to worry about different cases, I suggest this one that is a bit easier to read/understand if you don't have much experience with list comprehension:

def string_acumulator(input: str):
    output = []
    for i, letter in enumerate(input):
        repetition = i+1
        word = letter * repetition
        output.append(word.capitalize())
    return '-'.join(output)

print(string_acumulator('HELLO'))
>>> H-Ee-Lll-Llll-Ooooo
print(string_acumulator('hello'))
>>> H-Ee-Lll-Llll-Ooooo
Mario Apra
  • 93
  • 5
1

Use list comprehension:

input = "hello"
print('-'.join([i.upper()+i*n for n,i in enumerate(input)]))
Sup
  • 191
  • 5