Write a programExercise 4/4Intermediate30 XP
All words from the letters a, b, c
Task
Write a recursive function slova(dlzka) that returns a list of all words of the given length made of the letters a, b and c, in alphabetical order. Letters may repeat.
slova(1)returns["a", "b", "c"],slova(2)returns["aa", "ab", "ac", "ba", …, "cc"]- 9 words in all,slova(0)returns[""]- the only word of length 0 is the empty one.
Do not use the itertools module.
Examples
Call
print(slova(1))
Expected output
['a', 'b', 'c']
Call
print(slova(2))
Expected output
['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']
Rules
Solve it with recursion - without the
itertoolsmodule.
After you submit, 3 hidden tests will also check your solution: length 0, length 3, length 4.
Python starts the first time you run code.
Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.
Input (stdin)
Each line = one call to input().
Output
Hints
Try it yourself first. Each hint reveals a little more - and lowers the reward a little.
Signed out, hints are free - but no XP is awarded either.
Solution
The solution unlocks after the last hint.