Skip to content
Lesson 1 of 9 Free Preview
Duration: 20 min

What Is AI, Really?

Learn it

Artificial intelligence is computers doing tasks that seem to need intelligence. Most modern AI is machine learning: instead of writing every rule, we give examples (data) and the computer finds patterns. AI can be very useful and also make mistakes or reflect bias in its data.

🧰 Tool: any free online Python editor such as Online Python or Trinket, or install Python from python.org and use IDLE.

Code examples

Rule-based vs learning

# Rule-based: a human writes the rules
def is_spam_rules(message):
    return "free money" in message.lower() or "click now" in message.lower()

# Learning-based (idea): count words seen in labelled examples
examples = [("win free money now", True), ("see you at practice", False),
            ("click now for a prize", True), ("homework is due friday", False)]
spam_words = {}
for text, is_spam in examples:
    for word in text.split():
        spam_words[word] = spam_words.get(word, 0) + (1 if is_spam else -1)

def is_spam_learned(message):
    return sum(spam_words.get(w, 0) for w in message.lower().split()) > 0

print(is_spam_learned("free prize now"))   # True
print(is_spam_learned("practice friday"))  # False

Project: AI spotter

  1. List 5 places you meet AI (recommendations, maps, voice assistants…).
  2. For each, guess what data it learned from.
  3. Add 4 more labelled examples to the spam learner and test it.

Challenge: Find a message that fools the learner and explain why.

Enjoying this lesson?

Enroll in the full course to access all lessons, track your progress, and earn a certificate.

Enroll in Full Course