The dict_key contains the correct spelling and its corresponding value contains the spelling of the candidate
The function should identify the degree of correctness as mentioned below:
CORRECT, if it is an exact match
ALMOST CORRECT, if no more than 2 letters are wrong
WRONG, if more than 2 letters are wrong or if length (correct spelling versus spelling given by contestant) mismatches.
and return a list containing the number of CORRECT answers, number of ALMOST CORRECT answers and number of WRONG
My program assumes that all the words are in uppercase and max word length is 10
Here is my code:
def find_correct(word_dict):
#start writing your code here
correct_count=0
almost_correct_count=0
incorrect_count=0
for k,v in word_dict.items():
if len(k)<=10:
if len(k)==len(v):
if k==v:
correct_count+=1
else:
for i in k:
i_count=0
#print(i)
for j in v:
#print(j)
if not i==j:
i_count+=1
break
if i_count<=2:
almost_correct_count+=i_count
else:
incorrect_count+=i_count
else:
incorrect_count+=1
else:
incorrect_count+=1
print(correct_count,almost_correct_count,incorrect_count)
Driver Code:
word_dict={"WhIZZY":"MIZZLY","PRETTY":"PRESEN"}
print(find_correct(word_dict))
My Output: 0,2,0
Expected Output: 0,0,2