How to Use AI Prompts to Code, Debug & Automate Like a Pro (Python, Java, SQL, Excel)

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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top