DEV Community

Cover image for ChatGPT - Prompts for Writing and Generating Codes
Sandeep Kumar
Sandeep Kumar

Posted on • Updated on

ChatGPT - Prompts for Writing and Generating Codes

ChatGPT Prompts for Writing and Generating Codes:

Sharing a list of the prompts that can help you to use ChatGPT more efficiently.

Replace the words in block to get the desired result, for example, replace the language with a choice of your language, i.e., C#, JavaScript, Python, NodeJS, etc.

Initial Prompt Example
1 Create Create a code snippet for a specific programming task or function. Create a code snippet for Checking if a file exists in Python.
2 Create Create a code snippet for a specific algorithm or data structure. Create a code snippet for Checking for substrings in C#
3 Create Create a function that function description in language. Create a function that merges two lists into a dictionary in JavaScript.
4 Create Create a language function to task-description. Create a C# function to swap two numbers.
5 Create Create a language script to sort an array of data-type. Create a Python script to sort an array of strings.
6 Create Create a language function that converts data-type A into data-type B. Create a Java function that converts an integer array into a string array.
7 Create Create a language function to task-description with the following inputs: input-variables. Create a JavaScript function to return the sum of the given array with the following inputs: [17, 18, 15, 19, 14].
8 Create Create a language program that reads input-file-type, performs operations, and then writes the results to output-file-type following the format: describe-format. Create a C# program that reads a string array, performs sorting, and then writes the results to a CSV file.
9 Create Create a language script to parse file-format, extract information, and store the data in data-structure with the following requirements: requirements-list. Create a Python script to parse the CSV file, extract the first column, and store the data in a string array with the following requirements: skip the header row.
10 Create Could you create a language function to task, which takes in input-variables and returns output, under these constraints constraints-list? Could you create a C# function to add two numbers, which takes in 2 integers and returns the sum of given numbers?
11 Create How do I create a class in language with these attributes: attributes-list? How do I create a class in C# with custom attributes?
12 Demonstrate Give me a code snippet demonstrating how to use a specific library or tool in language. Give me a code snippet demonstrating how to use HealthChecks in .NET Core.
13 Develop Develop a language script that describes the functionality. Develop a Python script that generates a random and strong password.
14 Develop Develop a language function to perform task using library or methodology with the inputs: input-variables. Develop a C# function to Zip all the files using the DotNet Zip library with the inputs: array of files.
15 Develop Develop a language program to read file-type, perform operations, and write the results to output-format. Develop a C# program to read CSV files, skip the header row, and write the results to DataTable.
16 Generate Generate a program that reads input-source and outputs desired-output in language. Generate a program that reads an integer array and outputs a reversed array in JavaScript.
17 Generate Generate a sample code for specific library or framework usage. Generate a sample code for .NET Core SignalR usage.
18 Generate Generate a sample code for specific task/algorithm. Generate a sample code for Bubble sorting.
19 Generate Can you generate a language code that implements data structure or algorithm? Can you generate a Java code that implements Transpose of a Matrix?
20 Generate Can you generate a code snippet for specific algorithm/data structure in programming language/technology/framework? Can you generate a code snippet for Huffman Encoding in JavaScript?
21 Generate Come up with a code snippet for a specific UI component or feature. Come up with a code snippet for a Toast component usage in Angular.
22 Implement Implement a language function to handle task. Implement a C# function to handle exceptions.
23 Implement Implement a language program that reads input and writes output. Implement a JavaScript program that reads two integer arrays and writes a merged array.
24 Implement Implement a language script that reads file-format and stores them in database. Implement a Python script that reads CSV files and stores them in SQLLite.
25 Implement Implement a language API that reads the input-type and generates a output, and then stores it in database. Implement a Python API that reads the character array, and generates a random key using these characters, and then stores it in SQLite DB.
26 Implement Implement a language algorithm for task that takes input-parameters and returns the output. Implement a C++ algorithm for recursion that takes an array and returns the Mean of the given array.
27 Implement Implement a language algorithm for task using constraint. Implement a C# algorithm for the factorial of a number using recursion.
28 Provide Provide a language code to perform file operations like file-operations-list. Provide a C# code to perform file operations like Open, Read, Write, and Close.
29 Provide Provide a code snippet for handling specific error or exception in language. Provide a code snippet for handling SQL exceptions in C#.
30 Provide Please provide a code snippet for specific functionality in language/technology/framework. Please provide a code snippet for Decimal to Binary Conversion in Java.
31 Provide Can you provide a language script to parse file-format? Can you provide a Python script to parse CSV files?
32 Rewrite Rewrite this language code: [enter your code here] Rewrite this C# code: [enter your code here]
33 Rewrite Rewrite this language code using specific feature or method: [enter your code here] Rewrite this JavaScript code using recursion: [enter your code here]
34 Solve Can you help me code a language algorithm to solve the problem given the constraints: constraints-list? Can you help me code a C# algorithm to solve the memory leakage problem?
35 Solve Come up with a solution that solves problem-description in language and explain how it works. Come up with a solution that solves the diamond problem in Java and explain how it works.
36 Want to Act I want you to act as a web developer and write HTML and CSS code for a specific type of web page, with specific features. I want you to act as a web developer and write HTML and CSS code for an accordion, with drag and drop feature.
37 Want to Act I want you to act as a language programmer and create a program that does something specific using a specific library. I want you to act as a C# programmer and create a program to create a chatbot using Signalr.
38 Want to Act I want you to act as a data scientist and write language code to clean, analyze, visualize, or model a dataset on a specific topic. I want you to act as a data scientist and write R language code to clean, analyze, visualize, or model a dataset on a specific topic.
39 Want to Act I want you to act as a mobile app developer and write language code to create a specific feature for an Android app. I want you to act as a mobile app developer and write Flutter code to create a notification widget for an Android app.
40 Want to Act I want you to act as a game developer and write language code to create a specific game mechanic for a 2D platformer game. I want you to act as a game developer and write C# code to create a specific game mechanic for a 2D platformer game.
41 Want to Act I want you to act as a code generator and provide a language/technology/framework code snippet for a specific task. I want you to act as a code generator and provide a .NET Core code snippet for Swagger implementation.
42 Want to Act I want you to act as a language developer and write a function that takes a data type as an input and returns the output. I want you to act as a Python developer and write a function that takes a character array as input and returns the concatenated string.
43 Want to Act As a web developer, I need you to generate a number by number grid of HTML divs with a color background. As a web developer, I need you to generate a 10 by 10 grid of HTML divs with a Grey background.
44 Write Write a program that program description. Write a program that merges 2 arrays.
45 Write Write a function in language to calculate the mathematical concept. Write a function in JavaScript to calculate the random string.
46 Write Write a language program that performs task using library or algorithm. Write a C# program that connects to SQL Server using Dapper.
47 Write Write a language script that reads from data source and outputs to data destination. Write a Python script that reads from CSV and outputs to an HTML table.
48 Write Write a language script to perform the operation. Write a PowerShell script to automate the API version numbering.
49 Write Write a language script to connect to a database and perform database operation. Write a Python script to connect to a database and perform CRUD operations.
50 Write Write a language script that interacts with database and performs operations. Write a Python script that interacts with the database and performs the Delete operation.
51 Write Write a language script to connect to database and execute operation. Write a NodeJS script to connect to SQLite and execute CRUD operation.
52 Write Write a language script to parse file-format, extract information, and store the data in data structure following these requirements: requirements-list. Write a NodeJS script to parse CSV, extract data, and store the data in a table following these requirements: Skip the header row.
53 Write Write a language function to calculate a mathematical concept using algorithm. The function should take these inputs: input-variables and return desired-output. Write a C# function to find the Fibonacci series of n using recursion. The function should take these inputs: input-variables and return desired-output.
54 Write Write a language function named function name that performs a task. Write a Java function named ToTitleCase that converts the string into a Title Case.
55 Write Write a language function to find the n-th element in a data structure. Write a C# function to find the n-th element in a given array.
56 Write Please write a language function named function name to task. Please write a C# function named CalculateFactorial to calculate the factorial.
57 Write Show me how to write a language function that performs specific task. Show me how to write a C# function that performs logging into the database.
58 Write Write a language function for specific algorithm/data structure. Write a JavaScript function for Array Rotation.
59 Write Write a program task/algorithm Write a program to Check Whether a Character is a Vowel or Consonant
60 Write Write a program in language to perform file operation Write a program in C# to check if the file exists.

NOTE:

Check here to review more prompts that can help the developers in their day-to-day life.

Top comments (3)

Collapse
 
rajkumar_arulambalam_3aef profile image
Rajkumar Arulambalam

Thank you very much. Here's the series of steps ChatGPT said it takes to convert text into code:

  1. Semantic Comprehension: ChatGPT analyzes the natural language description provided in the prompt and extracts the key concepts, relationships, and structures inherent in the program or system of programs being described. It identifies the entities, actions, attributes, and relationships described in the text and interprets their significance within the context of the program's functionality and architecture.

  2. Ontological Representation: Based on its semantic comprehension of the description, ChatGPT constructs an ontological representation or conceptual model of the program. This model captures the essential elements of the program, including its components, interactions, dependencies, and behaviors. It organizes this information into a structured format that reflects the hierarchical and relational nature of the program's design.

  3. Serialization: Once the ontological representation is constructed, ChatGPT serializes this structured information into a format that can be effectively processed and utilized within its neural network architecture. This serialization process involves encoding the ontological model into a format compatible with the internal representation and processing mechanisms of ChatGPT, enabling it to manipulate and reason about the program's structure and behavior.

Collapse
 
risclover profile image
Sara (Risclover)

Hi! As-is, this is confusing to read. It would be helpful if you could provide an example for each.

Collapse
 
techiesdiary profile image
Sandeep Kumar

@risclover - added examples for each prompt, hope that helps.