Ctrl K

Playground Word Cipher

Easy
Kids in the yard invented a cipher for passing notes. You get a phrase text: words of English letters (lowercase and uppercase) separated by single spaces. Each word is encoded like this: 1. If the word starts with a vowel (a, e, i, o, u in either case), it stays as it is. Otherwise its first letter moves to the end of the word. 2. ma is appended to the word. 3. Then letters a are appended, as many as the word's position in the phrase counting from 1: one for the first word, two for the second, and so on. Return the encoded phrase, with the words separated by single spaces.
Example 1
text='Every cat likes milk' → 'Everymaa atcmaaa ikeslmaaaa ilkmmaaaaa'

Every starts with a vowel and gets ma + a; cat moves its first letter to the end: atc + ma + aa; then ikesl + ma + aaa and ilkm + ma + aaaa.

Example 2
text='Up we go' → 'Upmaa ewmaaa ogmaaaa'

A capital U is a vowel too, so Up keeps its letters in place.

Example 3
text='x' → 'xmaa'
Constraints
  • 1 ≤ len(text) ≤ 150
  • text consists of English letters and spaces
  • Words are separated by exactly one space, with no leading or trailing spaces
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
text='Every cat likes milk'
Expected
'Everymaa atcmaaa ikeslmaaaa ilkmmaaaaa'

Run checks the first 3 tests in your browser. Submit checks all 138 tests on the server, hidden ones included.