Welcome to Module 3 of our Prompt Engineering Course on impranjalk.com. In this post, youโll learn how to use AI prompts to:
- Generate code (Python, Java, SQL)
- Debug issues
- Automate Excel/Sheets tasks
- Create custom functions
- Understand how prompt types and structures impact output quality
Whether you’re a developer, student, or busy professional, this guide will save you hours and improve your daily workflow.
โ 1. Generate Python, Java, SQL using Prompts
LLMs like ChatGPT can generate production-ready code if prompted well. Use role-based instructions, input/output clarity, and examples to get precise results.
๐ ๏ธ Python Prompt (Role + I/O Format)
Role: You are a Python expert.
Task: Write a function to find the second largest number in a list.
Input: [5, 1, 8, 3, 2]
Output: 5
Include: Edge case handling, input validation, and comments.
๐ ๏ธ Java Prompt (Role + Sample Usage)
Role: You are a senior Java developer.
Task: Create a class `Employee` with:
- Fields: int id, String name, double salary
- Method: getYearlySalary() that returns salary * 12
Also: Add constructor, toString(), and main() to test the output.
๐ ๏ธ SQL Prompt (Instruction + Input Table)
Role: SQL expert.
Task: Write a query to retrieve the top 5 highest-paid employees.
Input Table: employees(id INT, name VARCHAR, salary DECIMAL)
Expected Output: name, salary ordered by salary DESC LIMIT 5
๐ก Use-cases: Prototyping, assessments, or fast development.
โ 2. Debugging Code with ChatGPT
Use step-by-step prompting (Chain-of-Thought) to debug more effectively.
๐ Python Debug Prompt
Role: You are a Python code reviewer.
Code Snippet:
my_list = [10, 20, 30]
print(my_list[3])
Task: Identify the error, explain why it happens, and fix it with a safe version.
Output: Explain fix with inline comments.
โ Java Debug Prompt
Role: Java bug fixer.
Code Snippet:
String name = null;
System.out.println(name.length());
Task: Resolve the NullPointerException. Explain how to avoid it using null checks or Optional.
๐ง Best practice: Paste full stack traces and describe expected behavior.
โ 3. Automate Excel + Google Sheets with Prompts
LLMs can write complex formulas and even full Google Apps Scripts.
๐ง Google Sheets Prompt
Role: Google Apps Script developer.
Task: Write a script that sends an email when any cell in Column C of 'Tasks' sheet is updated.
Email should include: updated row content and timestamp.
๐ค Excel Formula Prompt
Task: Extract domain name from email in A2.
Example: If A2 = pranjal@example.com โ Output: example.com
Formula: =RIGHT(A2,LEN(A2)-FIND("@",A2))
๐ฅ Combine with tools like Zapier or Make.com for full automation.
โ 4. Create Custom Functions using Prompts
LLMs can help you create mini tools tailored to your needs.
๐ JavaScript Function Prompt
Role: JavaScript engineer.
Task: Create a function getDayOfWeek(dateStr) that returns the weekday for input like '2025-05-22'.
Add: Validation for invalid date format and handle edge cases.
๐๏ธ Excel Custom Formula Prompt
Task: Create an Excel custom formula to count number of weekends between two dates.
Input: A1 = 01/05/2025, B1 = 10/05/2025
Expected Output: 3
๐งฉ Great for building micro-solutions into your workflows.
๐งฉ Understanding Prompt Types & Structures
Now that you’ve seen real-world prompts, letโs understand the techniques behind them.
๐น Zero-shot Prompting
Give no examples โ just clear instructions.
Example:
Write a SQL query to get the average salary from the employees table.
โ๏ธ Best for simple or well-known tasks.
๐น Few-shot Prompting
Provide examples before the main prompt.
Example:
Input: [3, 2, 1] โ Output: 2
Input: [10, 20, 5] โ Output: 10
Now, Input: [9, 5, 8] โ Output:
โ๏ธ Best when format matters or the task is abstract.
๐น Chain-of-Thought Prompting (Step-by-Step)
Ask the model to explain reasoning before answering.
Example:
What is the square of the sum of 2 and 3?
Letโs think step-by-step.
โ๏ธ Best for logical or multi-step problems.
โ๏ธ Instruction + System Message Prompts
Break prompts into clear sections to guide AI better.
๐๏ธ Instruction + Input + Output
Instruction: Generate a Python function to check for palindromes.
Input: 'madam'
Output: True
๐ก๏ธ System + User Message
System: You are a Python tutor. Be detailed and correct.
User: Write a function that reverses a string.
โ๏ธ Best for app-based integration or when controlling tone.
๐ฌ Final Thoughts
๐ง โPrompt engineering is not just about asking โ itโs about asking smart.โ
By using prompt types like zero-shot, few-shot, and step-by-step along with clear formatting, you unlock the real power of AI.
Start practicing these techniques in your own projects, automation flows, and learning journeys.
๐ Bookmark this blog on impranjalk.com for daily reference.