ICT582 Python Revision
🎯 Learning Objectives
πŸ“š Key Concepts

Algorithm vs Program

An algorithm is a step-by-step plan (in human language or pseudocode) for solving a problem. A program is the algorithm written in a programming language (like Python) that a computer can execute.

Why Python?

Python is simple to read, widely used in data science, AI and engineering, and is an object-oriented language. It is interpreted β€” you can run code line by line in the Python shell (IDLE) or run a .py file.

Variables

A variable is a named storage location in memory. You create a variable by assigning a value with =.

name = "Alice"
age  = 20
gpa  = 3.8
is_enrolled = True

Variable names: start with a letter or _, no spaces, case-sensitive (Age β‰  age).

Python Data Types

TypeExampleDescription
int42Whole number
float3.14Decimal number
str"hello"Text (in quotes)
boolTrue / FalseTrue or False
NoneTypeNoneNo value / absence of value

Every value in Python is an object of some class. Use type(x) to check.

print() β€” Output

print("Hello, World!")        # Hello, World!
print("Name:", name)          # Name: Alice
print(age, gpa)               # 20 3.8
print("Sum:", 3 + 4)          # Sum: 7

input() β€” User Input

input() always returns a string. Convert it if you need a number.

name = input("Enter your name: ")
age  = int(input("Enter your age: "))
gpa  = float(input("Enter GPA: "))

Comments

Use # for single-line comments. Comments are ignored by Python β€” they explain the code to humans.

# This is a comment
x = 5   # inline comment

type() and isinstance()

x = 42
print(type(x))            # <class 'int'>
print(type("hello"))      # <class 'str'>
print(isinstance(x, int)) # True
πŸ’» Code Examples

Example 1 β€” First program

# A simple Python program
print("Welcome to ICT582!")
name = input("What is your name? ")
print("Hello,", name)

Example 2 β€” Variables and types

age   = 21
height = 1.75
name  = "Bob"
active = True

print(type(age))     # <class 'int'>
print(type(height))  # <class 'float'>
print(type(name))    # <class 'str'>
print(type(active))  # <class 'bool'>

Example 3 β€” Input and simple calculation

price = float(input("Enter price: "))
qty   = int(input("Enter quantity: "))
total = price * qty
print("Total:", total)
⚠️ Exam Focus
  1. Know the difference between an algorithm and a program β€” expect a definition question.
  2. Be able to identify what data type a value is (int, float, str, bool).
  3. Know that input() always returns a str β€” you must convert it with int() or float() to do arithmetic.
  4. Write a short program that takes user input and prints output β€” a common exam question.
  5. Know that Python is an object-oriented language and every value is an object.
❌ Common Mistakes
⚑ Quick Recap
← Previous Topic 02: Expressions β†’