Common Mistakes
Repeated Mistakes
1. Unit conversion
The given units of variables do not necessarily give out the results of the desired unit, even if you follow the proper steps of calculation. Keep in mind that as much as this is a computation course, we still are working on physics problems. Therefore, we need to follow the units in the equations.
2. Definition of constants
There are different unit systems, such as SI or cgs. Some constants need to be defined in specific units, such as G = 6.67e-11, which is the gravitational constant in the SI unit system with a unit N*m^2/kg^2.
3. Definition of incorrect constant
k is sometimes used as the Coulomb constant in electrostatics and sometimes used to denote the Boltzmann constant. Make sure that you are using the correct one by checking the value.
4. Incorrect use of e
In calculators and Python language, e is used to define powers of 10, such as:
# these are correct definitions of the gravitational constant
G = 6.67e-11
G = 6.67 * 10**(-11)
# this is an incorrect definition of the gravitational constant
G = 6.67 * e**(-11)
5. Percent calculations
In some problems, you need to make sure that the percentage actually adds up to 100. One way to do that is to define another set of variables whose values are 100 to follow through with the calculations.
6. Degrees/Radians
math library has trigonometric functions that take in the arguments in radians and their inverses return the value in radians as well. So, if you need a degree version, you need to convert the value you have as radians.
7. Mismatched variable names
Sometimes, you define a variable and use that variable in operations with the given name, and that code block does not work as intended. However, when you delete that block, you might still be calling a variable defined in that block.
This mistake can be overcome by running your code before submissions.
8. Incorrect number of print() command
You need to print the number of variables you are asked to use in your code. If the instructions seem unclear, please ask during the lab sessions. More or fewer number of prints will cost your grade.
9. Input asked, none given
If the question asks for a specific number of inputs and you do not use input() command, then the automatic evaluation will treat that as incorrect, and you will probably get a zero grade.
10. Incorrect format
If the question asks for a specific number of inputs and you use input(s) in an incorrect format (i.e. one that is not given in your lab.py file), then the automatic evaluation will treat that as incorrect. You will probably get a zero grade. Here are some of the most common versions of incorrect input format:
### Example 1
# this is an example of the most common incorrect input
x = input('enter x value here')
# this is the corrected version
x = float(input())
### Example 2
# this is an example of an incorrect input
MYINPUTS = "1|2"
E_n = float(MYINPUTS)
# this is the corrected version
MYINPUTS = "1|2"
E_n = float(input())
### Example 3
# this is another example of an incorrect input
N, x_0 , r = map(float, MYINPUTS.split("|"))
# this is the corrected version
N, x_0, r = float(input()), float(input()), float(input())
# this is another corrected version
N = float(input())
x_0 = float(input())
r = float(input())
### Example 4
# this is again another example of an incorrect input
A = eval(MYINPUTS)
# this is the corrected version
A = input()
11. Multiple Operations
Performing the operations multiple times alerts the automatic evaluation process that an incorrect operation is being performed, and this costs you your grade.
12. Incorrect print Format
Automatic evaluation checks your results as the question asks. You can write your comments in a comment line but the evaluation process will check your prints as your results. So even though the operations you carry out are the ones that are asked, going a mile further to do a job will be seen by the machine as doing an incorrect job. See the example below.
# this is an example of the most common incorrect print
print("The result of the operation 2+7=", 2+7)
# this is the corrected version
print(2+7)
13. MYINPUTS Explained
(a) How do you get what the user "typed" from the keyboard
Use input() function:
x = input()
Don't forget that what you "inputted" with input() is always a string
To convert inputted string into "sensible" numbers, you have to use another function: int()
x = int(input()) # this converts typed string into integers
(b) Why do you need to use this variable named MYINPUTS?
VPL evaluation procedure is strict and hidden.
Background evaluating code cannot process your inputs
Therefore, you have to store "your input" into a single variable
This variable stores all your "input" stuff as a single string, and values are separated with "|" (pipe)
MYINPUTS = "VALUE1|VALUE2" # this string holds two values
This is not enough; you have to also supply an input() for every value you mention. See also explanation of input() above. Therefore:
MYINPUTS = "VALUE1|VALUE2"
v1 = int(input())
v2 = int(input())
Now, you can operate on v1 and v2 within your code.
(c) Important Notes
When you use MYINPUTS as input values, you don't need to type values on the keyboard. However, in Colab, input() functions become available, and you have to type individual values one by one.
In VPL, your input() functions should not include any arguments, i.e. no extra stuff in between parentheses:
x = int(input("Type an integer: ")) # WRONG for VPL; it cannot evaluate; but correct for CoLab
y = int(input()) # CORRECT for VPL