Python Practice Test Feedback
Python Practice Test Feedback
In the IT sessions, the TAs will also go through the questions and provide additional
feedback to you if needed.
The correct answer for the 1st question (for example):
def multiply_numbers(a,b,c):
answer= a*b*c
return answer
1. We don't define the default values for a,b,c. This will allow us to have a flexible function.
Whatever we call the function, this function can return the correct answer.
2. Indentation error. Python is very sensitive to the indentation. If this is not correct, the
code cannot run.
def multiply_numbers(a,b,c):
"""insert the code that performs the operation.
Use the variable 'number' to hold and return the value """
# YOUR CODE HERE
a=1
b=2
c=3
result=multiply_numbers (a,b,c)
" Check your code here "
" Assign random input variables and check the answer"
" For example:"
3. Forget to “return” the results. In the Python function, you need to return your calculated
values. For example, in Q1, you need to type “Return number”
4. Always print the results so that you know if it is done correctly. The print command
should be similar with my example.
5. When we call a Python function, we will give the function some input values directly,
instead of prompting a command like "input ()" here. If you do this again in the Python
coursework, you will get ZERO mark, unfortunately. The autograder will not understand
the "input()"
def multiply_numbers():
a = int(input("Enter first integer:"))
b = int(input("Enter second integer:"))
c = int(input("Enter third integer:"))
number = a * b * c
print("The product of " + str(a) + ", " + str(b) + " and " + str(c) + "
is " + str(number))
return
multiply_numbers()
6. An example of our marking scheme, as you can see, we are trying to call the function
with different input values, if they are all correct, you will get the full mark.
assert multiply_numbers(3,4,5) == 60
assert multiply_numbers(2,2,2) == 8
assert multiply_numbers(-2,1,1) == -2
### END HIDDEN TESTS
7. Q4, most of the common mistake is from the usage of range(), as you know, range (n)
will give you the value from 0 to n-1. For instance, range(5) gives you 0,1,2,3,4. Therefore,
you should use range(n+1) instead of range(n).
for i in range(n):
e += (1**i) / math.factorial(i)
2. We don't define the default values for a, b, c. This will allow us to have a flexible
function. Whatever we call the function, this function can return the correct
answer.
4. Forget to “return” the results. In the Python function, you need to return your
calculated values. For example, in Q1, you need to type “Return number”
5. Always print the results so that you know if it is done correctly. The print
command should be similar with my example.
6. When we call a Python function, we will give the function some input values
directly, instead of prompting a command like "input ()" here. If you do this again
in the Python coursework, you will get ZERO mark, unfortunately. The autograder
will not understand the "input()"
7. An example of our marking scheme, as you can see, we are trying to call the
function with different input values, if they are all correct, you will get the full
mark.
8. Q4, most of the common mistake is from using range(), as you know, range (n)
will give you the value from 0 to n-1. For instance, range(5) gives you 0,1,2,3,4.
Therefore, you should use range(n+1) instead of range(n).
Also, I am attaching the common mistakes in the file, please check and avoid such
mistakes again.
9. Q5, the most common mistake is the wrong expression of the position. Some
students forgot ‘s0’.