Not a kata issue, you're using a fixed value a and that should depend on the value passed to your function.
Hi i'm getting this error while submitting my code, in my computer everything seems to be working okay:
Traceback (most recent call last):
File "tests.py", line 16, in
r = maskify(cc)
File "/workspace/default/solution.py", line 17, in maskify
n[i] = cc[i]
IndexError: list assignment index out of range
Here is my code:
cc = "fj4580"
cc = list(cc)
n = list(len(cc) * "#")
a = (len(cc)-1) - 4
while len(cc) <= 4:
i = 0
for i in range(len(cc)):
if i <= a:
n[i] = n[i]
n[i] = cc[i]
MY FIRST KATA!!!
Add the null case to your test code. Otherwise you teach how to write bad code.
C translation (author inactive)
not an issue
Please read this: https://docs.codewars.com/training/troubleshooting/
Not a kata issue, check which input makes your code fail.
This comment is hidden because it contains spoiler information about the solution
Firstly remove pass. it's only used when we need a statement, but don't want to put code, like for Java, we'd have to put some filler command like "System.out.print("");" in that function as it can't be empty.
Moving onto the question, since you're already reducing the length you need to act on ( for example, if your string is 'hello', then "len(string)-4" will imply, you'll just read 'h' ), so you don't need to use if-else.
Finally, you need to RETURN the encoded sting instead of printing it, so you'll have to convert that list back to a string.
I used the following code to do that:
codedstring = "".join(map(str, cc)
Also, in your function body use another variable name like "cc_new" instead of "cc" but that's just my opinion.( cc_new = list(cc) )
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse ,
Especially the third bullet point of this paragraph.
ok. Thank You.