Your code has syntax errors: Match this code with yours:
import difflib
employeeNames = ['Colton','Jayne','Barb','Carlene','Dick','Despina']
employeeNames.sort()
endInput = raw_input('Type "end" to view list of names.\n\n')
if endInput == "end":
userEmpName = raw_input("Please enter the employee name you're searching for. We'll return the best match on record.")
print difflib.get_close_matches(userEmpName, employeeNames, 1)
you didn't close the open brace in
input()
method.I suggest using
raw_input()
instead of usinginput()
while dealing with strings.you should use the
classname.method()
if you have imported only the class (in your caseimport difflib
) so usedifflib.get_close_matches(string,list,n)
instead.You need to use
print
statement before the returned value.
Also get_close_matches()
should be called inside of if
because if endInput!='end'
then NameError
will occur for userEmpName
.
EDIT:
I should have asked you about your python interpreter version.
The print line should use braces like this.
print(difflib.get_close_matches(userEmpName, employeeNames, 1))
The reason is in python 2.x
print is a statement
(as I mentioned in 4rth point) but in python 3.x
its a function
.