PCEP 1.1: Compilation vs. Interpretation Monday, August 12, 2024
https://edube.org/study/pe1
Programming = Writing instructions for computers to follow
Algorithm = Step-by-step solution to a problem
Program = Algorithm written in a programming language
Example Algorithm: Making a peanut butter sandwich
The Problem: Computers only understand machine code (0s and 1s)
Machine Code Example:
10110000 01100001 10110000 01100010
Human-Readable Code:
print("Hello, World!")
Programming languages bridge the gap between human thinking and computer execution.
Source Code → Compiler → Executable File → Computer Runs It
Source Code (hello.c):
#include <stdio.h> int main() { printf("Hello, World!"); return 0; }
Compilation Command:
gcc hello.c -o hello.exe
Result: hello.exe file that runs independently
Source Code → Interpreter → Direct Execution
Source Code (hello.py):
Execution Command:
python hello.py
Result: Code runs immediately through interpreter
Python Interpreter:
Benefits:
The basic building blocks of the language
Python Lexical Elements:
if
else
for
while
def
42
"hello"
True
+
-
==
and
How code must be written to be valid
Valid Python Syntax:
if x > 5: print("x is greater than 5")
Invalid Python Syntax:
if x > 5 print("x is greater than 5") # Missing colon
What the code actually does when executed
Syntactically correct but semantically wrong:
radius = -5 area = 3.14159 * radius * radius
The syntax is perfect, but negative radius doesn't make sense!
import this
Key principles:
Python prioritizes human readability over machine efficiency
High-Level (Python, Java, JavaScript):
Low-Level (Assembly, C):
Which statement about Python is correct?
A) Python is a compiled language that creates .exe files B) Python is an interpreted language that executes code line by line C) Python code runs faster than compiled languages D) Python requires compilation before execution
What we'll do:
Goal: Master PCEP 1.1 concepts through hands-on experience
Ready for hands-on practice!
Tomorrow: PCEP 1.1 continued - Lexis, Syntax, and Semantics
testing html comments
**Answer**: B - Python is an interpreted language