Troubleshooting Programming Errors
There three common types of error in computer programming.
Syntax, Sematic and Runtime error.
Syntax error occur when there is incorrect use of the programming language/ when you don’t follow the rules of the language.
You can troubleshoot syntax error by looking for missing or misplaced quote, parenthesis, or semi colon.
Semantic error is when the output you get is not what you expected.
You can solve this by cross checking the statements. A simple trick is to run your statements often so as to know where semantic error comes from.
Runtime error is when you give an undefined expression for the computer to run.
For example, 10 / 0
This is incorrect.
Whatever the error you get, you do a simple search in Stack overflow for the answer or Google it.
You can also go for a brisk walk to freshen up your mind then come back to your program.
Programming involves working with/manipulating data.
And variables are where these data is stored. See it as a container.
For example: age = 36
The variable name is age and 36 is the data stored in the container.
Another example: email_address = “Lorem.Ipsum@gmail.com”
Here a string of characters is stored in the variable name email_address.
Variable can fall into different categories depending on the type of data they store.
This is called Data Type.
The first example stored 36, an interger variable.
The second stored Lorem.Ipsum@gmail.com, a string variable.
Variable Naming Rules
A variable name can be letter(s), contain underscore and contain number.
It cannot start with a number, for example: 3cats is not a valid variable name.
It must not contain space e.g account number is not valid. Instead use account_number.
It cannot not be a keyword in the programming language, e.g. print.
It is case sensitive. Cat is different from cat.
Working with numbers
Basic + – * and / works as usual.
// is called FLOOR (J) and it is use to get just the main number before decimal point
For example: 5 // 3 will equal 1
The program discards .2
% is called MODULO and it gives just the remainder value
For example: 5 % 3 will equal 2
** is called EXPONENCE and it is use to calculate exponential value
For example: 2 ** 3 will equal 8
Working with Strings
Strings are used to store characters like letters or email address, and they are enclosed in double or single quotes depending on the context.
print (“Yes it is possible”)
print (‘He said “It is possible” every time’)
Observe the usage of double and single quotes in both example.
Both examples are correct.
Properly Using Whitespace
It is highly encouraged to use lots of whitespace in your source code to improve readability but not necessary.
One of the few instances that is important to use it is after declaring a keyword.
Are used to put a little note as reminder in our source code.
Or use to comment out some part of the program to prevent them from running.
The # sign begins a comment.
This is use to in expression to give TRUE or FALSE
A common type of this expression is the equality expression.
For example: you want to compare if 5 is the same as 5
5 == 4 the answer will equal FALSE
5 > 4 the answer is TRUE
2 != 3 the answer is TRUE
This is used to provide conditions in your program.