𓂀
𓋹

PYTHON & LOGIC GATES

Lesson 1 of 5
~6 hrs
WARMUP: Binary & Logic Icebreaker

Before we write code, let's understand how computers think. Computers don't understand words — they understand 1s and 0s (binary). Every piece of data, every image, every game is built from millions of tiny on/off switches.

# Can you decode this binary message? # 01001000 01100101 01101100 01101100 01101111 # Hint: 8 bits = 1 character (ASCII)

Discuss: What would happen if a single bit flipped in a bank transaction?

CORE CONCEPTS

Variables are like labeled boxes where you store data. Python makes this easy — just assign a value!

# Python Variables name = "Agent" age = 13 is_online = True # Logic Gates: AND, OR, NOT result = (age > 12) and is_online # True

Logic Gates are the building blocks of computing. AND outputs 1 only if both inputs are 1. OR outputs 1 if at least one input is 1. NOT flips the input.

Conditions let your code make decisions. Loops let it repeat tasks — essential for security scanners!

# Check password strength password = "cyber2024" if len(password) >= 8: print("Strong enough") else: print("Too short!") # Loop through a list of ports for port in [22, 80, 443]: print(f"Scanning port {port}")

Functions let you package code into reusable blocks — a key skill for any cyber tool builder.

def check_login(username, password): """Simple login validator""" if username == "admin" and password == "secret123": return "Access Granted" else: return "Access Denied" result = check_login("admin", "wrong") print(result) # Access Denied
MINI CHALLENGE: Fix the Bug

The following Python code should check if a user is old enough to access a system, but it has a bug. Can you spot and fix it?

# Buggy code age = input("Enter your age: ") if age >= 13: print("Access granted") else: print("Access denied")
Hint: What type does input() return? How do we compare numbers?
MAIN PROJECT: Login Simulator

Write a Python login simulator that stores a username and password, asks the user for credentials, and grants access only if both match. Use functions, conditions, and a loop to allow up to 3 attempts.

1

Define a login() function with two parameters

2

Store a hardcoded username and password

3

Add a loop that gives 3 attempts maximum

4

Return "Access Granted" or "Locked Out"

QUIZ: Python Basics

Test your understanding of Python fundamentals.

1. What operator checks if two values are equal in Python?

=
==
!=

2. Which data type represents a whole number?

string
int
float

3. What does for i in range(3): do?

Loop 5 times
Loop 3 times
Loop forever