Problems 2 and 3 are asking you to write a function. The code you put into the Moodle answer box is ONLY the definition of the function.
Any calls to the function that you put in Thonny to check that your function executes correctly are not part of the anwer for Moodle when the problem only says Write a function....