So, I am new to python and currently leading how to program basic functions with it. I have be asked to make a function which spell checks a word against the known correct spelling.
If the word is correct the function returns "correct", if there 2 or less mistakes it returns "almost" and if 3 or more mistakes are present the function returns "wrong". So for example if the function if of the formation
spell(correct, guess)
spell('hello', hello')
would return 'correct', spell('hello','nello')
would return 'almost', and spell('hello','hejje')
would return 'wrong'.
My code for this is:
def spell(correct, guess):
answer=list(guess)
right=list(correct)
w=0
for i in answer and right:
if answer[i]==right[i]:
w=w
else:
w=w+1
if w==0:
print("correct")
elif w==1 or w==2:
print("Almost")
else:
print("Wrong")
I trying to define the function by adding up the number of difference between the two lists. But I keep getting the error "list indices must be integers or slices, not str" and I don't know another way of setting up the problem. I want to know the best way to approach coding this so I can try and attempt my code to work.