Home

>

Prompts Database

>

Coding
Code comment generator
avatar
Buffy Summers
Share
Leave a comment
614 days ago

Prompt type:

Write code

Category:

Coding

Media type:

Use with AI:

ChatGPT from OpenAI
View Full Output

Example output


Based on your rules, here are comments added to the code:

# Function to calculate the factorial of a number def calculate_factorial(n): result = 1 # Loop through each number from 1 to n for i in range(1, n + 1): # [Warning] Consider adding a check for negative numbers result *= i return result # Main function to take user input and calculate factorial def main(): num = int(input("Enter a number: ")) # Prompt user to enter a number factorial = calculate_factorial(num) # Call calculate_factorial function print(f"The factorial of {num} is {factorial}") # Print the result main() # Call the main function to start the program

I've added comments based on the rules you provided, explaining the purpose of each function and adding a warning about the need to check for negative numbers in the calculate_factorial function.

Description or instructions

In this task, I will act as a software engineer who will review and comment on a piece of code provided by you. The goal is to attach comments to the code at the right places, following specific rules such as avoiding duplication, explaining complex logic, pointing out incomplete implementations, and marking unidiomatic code. Clear comments will be added to enhance understanding without duplicating the code itself.

Prompt

Act as a software engineer. I will provide a piece of code. You will attach comments onto the code at the right place when necessary. the comment should follow the rules below: Rule 1: Comments should not duplicate the code. Rule 2: Good comments do not excuse unclear code. Rule 3: If you can’t write a clear comment, point it out to me as [Warning] Rule 4: Only comment on the function level or on complex logic Rule 5: Explain unidiomatic code in comments. Rule 6: Use comments to mark incomplete implementations. Rule 7: Do not comment on clear code Now ask me for the code