Section 1
1. Introduction to AI-Assisted Coding
What is AI-Assisted Coding?
AI-assisted coding means using Large Language Models (LLMs) such as ChatGPT, Claude,
Gemini, or Copilot to help with:
● Writing code
● Explaining code
● Debugging
● Learning libraries
● Solving programming problems
● Understanding datasets
● Generating test cases
● Improving productivity
AI tools do NOT replace programming fundamentals.
They assist developers in:
● Faster development
● Better experimentation
● Faster debugging
● Improved learning
2. Traditional Coding vs AI-Assisted Coding
Traditional Workflow AI-Assisted Workflow
Search Google Ask LLM directly
Read documentation Ask AI to explain documentation
manually
Search StackOverflow Ask AI for debugging help
Write everything manually Generate starter code
Trial and error Iterative prompting
3. Important Reality About AI
AI is NOT always correct.
LLMs generate responses based on prediction patterns.
This means:
● AI can sound confident even when wrong
● AI may generate incorrect code
● AI may hallucinate functions/APIs
● AI may ignore edge cases
● AI may generate inefficient solutions
Therefore:
Never blindly trust AI-generated code.
Always:
● Validate logic
● Test outputs
● Check edge cases
● Understand the code
4. Skills That Matter in the AI Era
Earlier:
● Syntax memorization was important
Now:
● Problem-solving
● Prompt engineering
● Debugging
● Validation
● Reasoning
● Understanding requirements
● Breaking down problems
are MORE important.
5. What is Prompt Engineering?
Prompt engineering means:
Writing structured and effective instructions to get better AI outputs.
Good prompts improve:
● Accuracy
● Readability
● Explainability
● Relevance
● Code quality
6. Structure of a Good Coding Prompt
A strong coding prompt usually contains:
Component Purpose
Task What should AI do?
Constraints Rules/restrictions
Input/Output Expected format
Edge Cases Special conditions
Explanation Ask AI to explain
logic
Complexity Ask for optimization
Libraries Mention
allowed/disallowed
libraries
7. Weak Prompt Example
write python code for average
Problems:
● Average of what?
● No input format
● No constraints
● No explanation requested
Result:
● Generic or unclear output
8. Better Prompt Example
Write a Python function to calculate the average of numbers in a list.
Requirements:
- Do not use numpy
- Handle empty lists
- Add comments
- Explain time complexity
- Show example usage
Benefits:
● Clear task
● Proper constraints
● Better output quality
● More useful learning
9. Common AI Failure Modes
9.1 Hallucinations
AI may invent:
● functions
● libraries
● APIs
● syntax
Example:
pd.read_excel_csv()
This function does NOT exist.
9.2 Incorrect Logic
AI may:
● fail on duplicates
● fail on negative values
● fail on corner cases
9.3 Missing Edge Cases
AI often ignores:
● empty input
● null values
● invalid data types
9.4 Inefficient Solutions
AI may generate:
● unnecessary nested loops
● memory-heavy approaches
● non-optimized logic
Section 2 - QnA
Activity: Improve the Prompt using the CRAFT
Framework
For each prompt below, discuss with your partner and answer:
1. What's missing from this prompt?
2. How would you improve it using the CRAFT framework?
3. Rewrite the prompt.
Prompt 1 (Easy)
Weak Prompt
Write Python code to sort numbers.
Questions:
● What's missing?
● How would you rewrite this prompt?
Improved Prompt :
You are an experienced Python developer.
Write a Python function to sort a list of integers in ascending order without using the built-in
sort() or sorted() functions.
Requirements:
- Add comments to explain each step.
- Include sample input and output.
- Explain the algorithm used.
- Mention the time complexity.
Prompt 2 (Medium)
Weak Prompt
Help me analyze this CSV file.
Questions:
● What's missing?
● What additional information would you provide?
● Rewrite the prompt using CRAFT.
Improved Prompt :
You are a data analyst.
I have a CSV file containing employee information with columns such as Employee ID,
Department, Age, Experience, and Salary.
Using pandas, write Python code to:
- Load the dataset.
- Check for missing values.
- Display summary statistics.
- Identify the top 5 highest-paid employees.
- Visualize the salary distribution.
Explain each section of the generated code in simple terms.
Prompt 3 (Advanced)
Weak Prompt
Write code to find the best customers.
Questions:
● What does "best" mean?
● What information is missing?
● How would you make this prompt specific and actionable?
● Rewrite the prompt.
Improved Prompt :
You are an experienced Python developer.
Given a list of customer transactions in the format (Customer_ID, Amount), write Python code to
identify the top 3 customers based on their total spending.
Requirements:
- Do not use external libraries.
- Handle multiple transactions for the same customer.
- Explain your approach.
- Mention the time complexity.
- Include sample input and expected output.
- Add comments throughout the code.
Prompt 4 (Non-Coding)
Weak Prompt
Plan a trip for me to Singapore.
Questions:
● What information would the AI need before creating an itinerary?
● What assumptions is the AI forced to make?
● Rewrite the prompt using the CRAFT framework.
Improved Prompt :
You are an experienced travel planner.
Plan a 5-day trip to Singapore for two adults travelling in September with a budget of ₹1.5 lakh
(excluding flights).
We enjoy local food, sightseeing, and nature but prefer a relaxed itinerary over a packed
schedule.
Include:
- A day-wise itinerary
- Places to visit
- Recommended restaurants
- Estimated daily budget
- MRT/public transport suggestions
- One backup indoor activity for rainy weather
Present the itinerary in a table.
Section 3
Section 3 – Python Code Generation
Learning Outcomes
By the end of this section, learners will be able to:
● Generate Python code using LLMs.
● Improve prompts using the CRAFT framework.
● Validate AI-generated code.
● Debug incorrect code.
● Optimize existing solutions.
Activity 1 – Generate Code (10 mins)
Speaker Notes
"Let's start with a simple coding problem. Don't use ChatGPT immediately.
First, think about how you would solve it. Then we'll compare our approach
with AI's."
Problem
Find the second largest unique number in a list.
Example
Input:
[12,45,7,89,23]
Output:
45
Weak Prompt
Write Python code to find the second largest number.
Good CRAFT Prompt
You are an experienced Python developer.
Write a Python function to find the second largest unique number in a list of integers.
Requirements:
- Do not use sort() or sorted().
- Handle duplicate values.
- Handle invalid inputs such as empty lists.
- Explain the algorithm.
- Mention time complexity.
- Include comments and sample input/output.
AI Solution
def second_largest(nums):
unique = list(set(nums))
if len(unique) < 2:
return None
largest = second = float("-inf")
for num in unique:
if num > largest:
second = largest
largest = num
elif num > second:
second = num
return second
print(second_largest([12,45,7,89,23]))
Ask the Class
● Would you trust this solution?
● Which edge cases should we test?
● Could this be improved?
Key Takeaway
AI can generate working code quickly, but developers must validate correctness
and edge cases.
Activity 2 – Debugging with AI (10 mins)
Speaker Notes
"Now let's see how AI performs as a debugging partner."
Problem
The following code throws an error.
def average(nums):
total=0
for i in range(len(nums)+1):
total+=nums[i]
return total/len(nums)
numbers=[10,20,30,40]
print(average(numbers))
Weak Prompt
Fix this code.
Good CRAFT Prompt
You are a senior Python developer.
The following code throws an error.
Please:
- Identify the bug.
- Explain why it occurs.
- Correct the code.
- Suggest improvements.
- Mention edge cases that should be tested.
(Code below)
AI Solution
def average(nums):
if len(nums)==0:
return None
total=0
for i in range(len(nums)):
total+=nums[i]
return total/len(nums)
numbers=[10,20,30,40]
print(average(numbers))
Ask the Class
● What caused the error?
● Did AI explain it clearly?
● Would you test anything else?
Key Takeaway
AI is excellent at debugging, but explanations matter just as much as fixes.
Activity 3 – Code Optimization (10 mins)
Speaker Notes
"Working code isn't always efficient code. Let's see if AI can improve it."
Problem
def find_duplicates(lst):
duplicates=[]
for i in range(len(lst)):
for j in range(i+1,len(lst)):
if lst[i]==lst[j]:
[Link](lst[i])
return duplicates
Weak Prompt
Improve this code.
Good CRAFT Prompt
You are an experienced Python code reviewer.
Review the following code.
Tasks:
- Identify inefficiencies.
- Rewrite using a better algorithm.
- Explain the improvements.
- Compare time complexity.
- Add comments.
(Code below)
AI Solution
def find_duplicates(lst):
seen = set()
duplicates = set()
for item in lst:
if item in seen:
[Link](item)
else:
[Link](item)
return list(duplicates)
Ask the Class
● Which solution is easier to read?
● Which scales better?
● Why is a set useful here?
Key Takeaway
AI can improve performance and readability—but you should understand why the
optimization works.
Activity 4 – Interview Question (12 mins)
Speaker Notes
"Let's finish with a coding interview problem."
Problem
Return the first non-repeating element.
Example
Input:
[4,2,4,5,2,3,5]
Output:
3
Weak Prompt
Solve this coding problem.
Good CRAFT Prompt
You are preparing me for a Python coding interview.
Solve the following problem.
Given a list of integers, return the first non-repeating element.
Requirements:
- Do not use external libraries.
- Explain your approach.
- Mention time complexity.
- Perform a dry run.
- Include comments.
- Suggest an alternative solution.
AI Solution
def first_non_repeating(nums):
freq = {}
for num in nums:
freq[num] = [Link](num,0)+1
for num in nums:
if freq[num]==1:
return num
return None
print(first_non_repeating([4,2,4,5,2,3,5]))
Ask the Class
● Would this answer pass a coding interview?
● Can you think of another approach?
● What happens if every element repeats?
Key Takeaway
LLMs can solve interview problems, but understanding the algorithm is more
important than copying the code.
Student Notes
AI Coding Workflow
Good Prompt
↓
Generate Code
↓
Read the Code
↓
Test Edge Cases
↓
Debug
↓
Optimize
↓
Use in Your Project
Best Practices
● Write specific prompts.
● Include constraints.
● Ask for explanations.
● Test edge cases.
● Review generated code.
● Never copy-paste blindly.
● Optimize when necessary.
Final Wrap-Up (3 mins)
Ask the class:
1. What was the biggest mistake AI made today?
2. What was the best prompt we wrote?
3. When would you use AI to generate code?
4. When would you avoid relying solely on AI?