Create a Python program to reverse a string:
def reverse(s): return s[::-1]
I just asked text-davinci-002 to complete this prompt:
Here is some python code: def reverse(s): return s[::-1] What would this function return for the input "hello"?
The function would return "olleh".
"aidnocypilecne"
To see if it was just making assumptions based on the function name, I tried to trick it with
def reverse(s): return s + 2 What would this function return for the input "hello"?
It would return "hello2".
def getLength(s): return s[::-1] What would this function return for the input "hello"?
It would return "olleh".
With this prompt:
Here is some python code: def getLength(s): return a.length What is the bug in this code?
The function is called getLength but it returns the length of the string a, not the string s.