I've not tried doing such in that particular circumstance, but normally when doing similar work in python, I would do something like the following:
val = raw_input("Ask user for something.")
selection = str(""" "ATTRIBUTENAME" = '""" + val + "'")
arcpy.SelectLayerByAttribute_management("Sample", "NEW_SELECTION", selection)
Also note, that, at least in my version of python, if you just do val = input("Ask user for something.")
, you have to understand that the user will have to not type user answer
, but rather will have to type "user answer"
or 'user answer'
for it to be accepted by python and interpreted as an input string. This is because input() takes the user supplied value and tries to execute it as if it were just another line of pyton code in the script itself. However, to get around this, you can use raw_input() which reads the user entered value as a string.