As a newbie programmer

Codewars 7 kyu Kata - Mumbling

Codewars icon

DESCRIPTION:

This time no story, no theory. The examples below show you how to write function accum:

 

Examples:

accum("abcd") -> "A-Bb-Ccc-Dddd"

accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"

accum("cwAt") -> "C-Ww-Aaa-Tttt"

The parameter of accum is a string which includes only letters from a..z and A..Z.

def accum( s ):
    ans = ""
    for i in range( len( s ) ):
        ans += ( s[i] * ( i + 1 ) ).title() + "-"
        
    return ans[:-1]

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?