Common Mistakes
Week 1 - Introduction to Lab
1. Specific input/output
The task asks for a specific number of inputs and outputs in a specific order; you might have a different number of these.
For example, check the sample tasks below.
Ask a user to put in a number.
Divide the given number by 2.
Show the result.
# this is the sample correct code
x = int(input('give a number'))
y = x/2
print(y) # number of outputs (i.e print() commands) is 1
# this is the sample __incorrect__ code
x = print('welcome to the code') # this causes the automatic evaluater to understand
# that you have given an output without taking input.
x = int(input('give a number'))
y = x/2
y # in some compilers, this does not print your result.
# always print() the result you want to show.
2. Specific Formatting
The task asks you to format the input or output specifically, you might have missed this formatting.
For example, see the following task list.
You evaluate a number, x ➔ 6.1348289400
Show that number with two decimal points ➔ 6.13
# this is the sample correct code
x = 6.1348289400
print("{:.2f}".format(x))
# this is the sample __incorrect__ code
x = 6.1348289400
print(x)
3. Syntax mistakes - Power Operation
In Python, the power of a number is taken as base**power unlike some other languages base^power.
In Python, the caret (^) is used for another operation named XOR (or exclusive or). This operation is similar to the ones used in the mathematical logic. These are completely different operations and should be used carefully.
x = 6**2
print(x) # this gives 36 as expected.
y = 6^2
print(y) # this gives 4.
4. Using a different set of variables
For example, you are given 15 and 2 in a division operation. You should use 15/2 to show that operation and not change any of the given numbers.
However, for the examples where you want to check the result you found with some hands-on calculations on paper, you might want to use simpler numbers to do the proof check. See the following example.
For the two vectors, find the difference vector r1-r2
# this is the sample correct code
# given set of numbers at the top of VPL file
r1 = [3,4,5]
r2 = [5,12,13]
# question asks "r1 - r2"
result = [r1[i] - r2[i] for i in range(len(r1))]
print(result)
# this is the sample __incorrect__ code
# given set of numbers at the top of VPL file
r1 = [1,1,1]
r2 = [5,3,3]
# question asks "r1 - r2" but r2 - r1 used,
# this is where you find a vector in the opposite direction.
result = [r2[i] - r1[i] for i in range(len(r1))]
print(result)