Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below.
The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

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 answers. 
Assume that the words contain only uppercase letters and the maximum word length is 10.

Also write the pytest test cases to test the program.

#PF-Assgn-48

def find_correct(word_dict):
    #start writing your code here
    key=[]
    value=[]
    count=0
    correct=0
    wrong=0
    atmost=0
    result=[]
    for i,j in word_dict.items():
            key.append(i)
            value.append(j)
    for i in range(len(key)):
        if(len(key[i])==len(value[i]) and key[i]==value[i]):
            correct+=1
        elif((len(key[i])==len(value[i]))==False):
            wrong+=1
        else:
            for j in range(len(key[i])):
                if((key[i][j]==value[i][j])==False):
                    count+=1
                    if(count>2):
                        wrong+=1
                        break
            if(count<=2):
                atmost+=1
            count=0
           
           
    result=[correct,atmost,wrong]
    return result
       


word_dict={"THEIR": "THEIR","BUSINESS":"BISINESS","WINDOWS":"WINDMILL","WERE":"WEAR","SAMPLE":"SAMPLE"}
print(find_correct(word_dict))


3 comments:

  1. def find_correct(word_dict):
    c1,c2,c3,cou=0,0,0,0
    for i in word_dict:
    if(word_dict[i]==i):
    c1=c1+1
    elif(len(word_dict[i])!=len(i)):
    c3=c3+1
    else:
    x=word_dict[i]
    for j in range(len(x)):
    if(x[j]!=i[j]):
    cou=cou+1
    if(cou<=2):
    c2+=1
    else:
    c3+=1
    cou=0
    list=[c1,c2,c3]
    return list





    word_dict={"THEIR": "THEIR","BUSINESS":"BISINESS","WINDOWS":"WINDMILL","WERE":"WEAR","SAMPLE":"SAMPLE"}
    print(find_correct(word_dict))

    ReplyDelete
  2. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for fre
    Hire Hacker

    ReplyDelete

Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

Write a python function,  find_correct()  which accepts a dictionary and returns a list as per the rules mentioned below. The input diction...