Computer Programming
Computer Programming
Computer Programming
What is Programming?
Types of Errors:
Designing or creating a set of instructions to ask the computer
1. Syntax errors – Occurs when the code violated the
to carry out certain jobs which normally are very much faster
syntax or the grammar of the programming language.
than human beings can do. The computer does what the
2. Logical errors – A mistake that the programmer made
program tells it to do.
while designing the solution to a problem.
It is the process of planning a sequence for a computer to
Syntax and logical errors are collectively known as bugs.
follow.
In Programming - A letter or word that serve as a temporary In many programming languages, variables are statically
storage that can represent any value. typed, meaning they are declared with a specific type that can't
change during their lifetime.
Pseudocode In contrast, Python uses dynamic typing, allowing variables to
be assigned and reassigned to different data types without
A method that allows a programmer to represent the algorithm
restriction.
in a more programming related way.
Variables are used to store up data for later use.
It is also called as false codes because it tend to look like a
programming language but can still be understood by a person
that has little understanding in programming. Common Datatypes:
Examples: String – Texts
Integer – Positive and Negative Numbers (No
1. Let numOne = 0, numTwo = 0, and sum = 0
decimal)
Input numOne and numTwo
sum = numOne + numTwo Float – Decimal numbers
Output sum Character – Single letter or symbol
Boolean – True/False
2. Let num = 0
Input num
Identifiers – The name of the variable which the user choose.
If num is an Even number
output “Even” Syntax:
If num is an Odd number (identifier = value)
output “Odd” firstName = “Computer”
LastName = “Programming”
Example:
Examples: Conditional Operators - Used to compare values inside of
conditional statements.
1. Create a program that will display the sum of 2
numbers inputted by the user.
3. Create a program that will compute for the gross If-Elif-Else Statement - Dealing with three or more conditions.
pay of employees. Input the rate per hour, number Example:
of hours worked, name and position of the if age >= 18:
employee. Display the name, position and gross print("Legal age")
pay. elif age >= 13:
print("Teenager")
name = input("Enter the employee's name: ") else:
pstn = input("Enter the position of the employee: ") print("Too young")
rph = float(input("Enter the rate per hour: "))
hw = float(input("Enter the number of hours worked: ")) Nested Conditional Statement – Dealing with conditions inside
gp = rph * hw a condition.
print(name) Example:
print(pstn) if age >= 18:
print("The gross pay of the employee is ", gp) if height >= 170:
print("Legal age and tall")
elif height >= 156:
Conditional Statements print("Legal age and average")
A statement that makes the program smarter, it makes the else:
program decides on what to do in certain condition. print("Legal age and short")
Example of Flowchart: