Course එකට ආපසු

Your First AI Code

30 මිනිත්තු🏋️Activity

🎯 Lesson Objectives

By the end of this lesson, you will:

  • Generate your first piece of AI-written code
  • Learn to READ code without fully understanding it
  • Identify basic code elements (variables, functions, print statements)
  • Practice asking AI to explain code to you

📖 Introduction: Reading Before Running

Here's an important principle for vibe coding:

The Reading Principle

You need to READ code before you can effectively WORK with code.

You don't need to memorize syntax or write code from scratch. But you DO need to:

  • Recognize what different parts do
  • Spot potential problems
  • Understand the flow of logic

Think of it like being a music producer — you don't need to play every instrument, but you need to hear when something sounds wrong.


🎮 The Workshop Task

We're going to create a simple program:

Goal: A Python script that asks for your birth year and tells you your age.

Why Python?

  • Clean, readable syntax
  • Perfect for learning to READ code
  • One of the most common languages

Why This Task?

  • Simple enough to understand
  • Complex enough to show real coding concepts
  • Has clear input → process → output

📝 Step 1: Write Your Own Prompt First

Before looking at examples, try writing your own prompt for this task.

The task: Ask AI to create a Python script that:

  1. Asks the user for their birth year
  2. Calculates their age
  3. Displays a friendly message with their age
📝

Reflection Journal

Saved privately on your device
0 characters
0 total characters

Take a minute to write this before moving on!


📝 Step 2: Compare With Example Prompt

Here's a well-crafted prompt using C.I.C. + Role:

Example Prompt (C.I.C. + Role)
You are a Python developer teaching beginners. Write a simple Python script that: 1. Asks the user for their birth year 2. Calculates their age (assume it's currently 2024) 3. Prints a friendly message with their age Include comments explaining each line so a beginner can understand.
ChatGPTClaude

Compare with your prompt:

  • Did you specify Python?
  • Did you ask for a friendly message?
  • Did you request comments/explanations?

🤖 Step 3: The Generated Code

Send the prompt and you should receive something like this:

Python
# Age Calculator Program
# Get the current year
current_year = 2024
# Ask the user for their birth year
birth_year_text = input("What year were you born? ")
# Convert the text input to a number
birth_year = int(birth_year_text)
# Calculate the age
age = current_year - birth_year
# Display a friendly message
print(f"Awesome! You are {age} years old this year! 🎂")

Note: Your AI's output might look slightly different — that's fine!


🔍 Step 4: Code Reading Scavenger Hunt

Now let's learn to READ this code. Look at the generated code and answer these questions:

Question 1: Find the Variables 🔎

Variables are like labeled boxes that store information. They're created using the = sign.

How many variables can you spot?


Question 2: Find the Math ➕➖

Look for the calculation that determines the age.

What symbol is used for subtraction?


Question 3: Find the Output 📤

The print() function displays text to the user.

What message will the user see?


Question 4: Find the Input 📥

The input() function asks the user to type something.

What question does the program ask?


Question 5: Find the Conversion 🔄

Notice there are TWO variables for birth year. Why?


📊 Code Reading Quick Reference

Here's what to look for when reading code:

PatternWhat It Usually Means
something = valueCreating/storing data (variable)
function()Doing some action
# textA comment (ignored by computer, helps humans)
"text" or 'text'A piece of text (string)
+, -, *, /Math operations
print()Display something to user
input()Ask user to type something
if, elseMaking decisions
for, whileRepeating something

🎓 Step 5: Ask AI to Explain

Now practice getting explanations from AI. Try these follow-up prompts:

Prompt for Line-by-Line Explanation:

Request Line-by-Line Explanation
Explain this code line by line like I've never programmed before: [paste the code here]
ChatGPTClaude

Prompt for Specific Part:

Ask About Specific Line
What does this line do? birth_year = int(birth_year_text)
ChatGPTClaude

Prompt for Concepts:

Ask for Simple Explanation
What is a variable in programming? Explain like I'm 10 years old.
ChatGPTClaude

🧪 Step 6: Modify Through Prompts

Now practice modifying code through conversation with AI.

Modification 1: Change the Message

Modification: Change Message
Change the message to say 'Happy Birthday! You're {age} years young!'
ChatGPTClaude

Modification 2: Add More Info

Modification: Add Feature
Also calculate and display what year the person will turn 100
ChatGPTClaude

Modification 3: Add Validation

Modification: Add Validation
Add a check: if someone enters a year after 2024, tell them 'You haven't been born yet!'
ChatGPTClaude

Try each of these. See how AI modifies the code based on your requests!


🔑 Key Code Vocabulary

After this lesson, you should recognize:

TermWhat It IsExample
VariableNamed storage for dataage = 25
StringText data"Hello World"
IntegerWhole number2024
FunctionAction that does somethingprint(), input()
CommentNote for humans# This is a comment
AssignmentStoring value in variablex = 5

✅ Completion Checklist

Before moving on, verify:

0/6

✅ Lesson Summary

What You Accomplished

  1. ✅ Wrote your first prompt for code generation
  2. ✅ Got AI to create a working Python script
  3. ✅ Analyzed the code to understand its parts
  4. ✅ Practiced asking AI for explanations
  5. ✅ Modified code through follow-up prompts

Key Insight

You don't need to memorize syntax. You need to recognize patterns and communicate clearly with AI.


📝 Mini Quiz

📝 Check Your Understanding

1/3

What does a variable do in programming?