The parameter to the nickname function was expected to be an int. An int is not subscriptable meaning if you had an int value stored in the variable year, the code year[2] would be invalid.
When testing the program, Moodle does not check the function separately so if your code accepted the parameter as a string and returns the correct string, Moodle doesn't detect the error at that point.
But, Moodle also tests the function separately, and when the test code passed an integer to the formal parameter of the nickname function and the code in the nickname function tries to use indexing on that variable, an error occurs.