ChatGPT Prompts for Programmers

Prompt:

Write a Python function to calculate the factorial of a given number. Example: def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) print(factorial(5))  # Output: 120

Arrow

Prompt:

Create a JavaScript function to find the maximum element in an array. Example: function findMax(arr) { let max = arr[0]; for (let i = 1; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; } } return max; } console.log(findMax([3, 7, 2, 8, 5]));  // Output: 8

Arrow

Prompt:

Implement a function in Python to check if a given string is a palindrome. Example: def isPalindrome(s): s = s.lower() return s == s[::-1] print(isPalindrome("Madam"));  # Output: True