Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+5 votes

When testing the entire program, I get the correct outputs. However, the last test on moodle it tests the function alone. It does not produce an output and gives an error 'TypeError: 'int' object is not subscriptable'. What does this mean?

asked in old_CSC201 by (8 points)

1 Answer

+1 vote

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.

answered by (8 points)