You are using Python 2.
Run
import sys
print(sys.version)
and it will probably output something like
2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
which means that you are using Python 2.
As roganjosh pointed out, Python 2's turtle module does not have the command textinput. If you want to run that code, you need to use python 3. If you are unsure how to switch versions, leave a comment on this post saying how you installed Python, and how you run your programs, and I'll show you how to use Python 3 instead.
If you want to continue with Python 2, then instead of that command you have to run
import tkSimpleDialog
answer = tkSimpleDialog.askstring("Text", "Text")
which does exactly the same thing.