Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f64aa1b

Browse files
Create Assignment on Dictionary - Level 2.py
1 parent fb9d3f7 commit f64aa1b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'''
2+
Problem Statement
3+
Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below.
4+
The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.
5+
6+
The function should identify the degree of correctness as mentioned below:
7+
CORRECT, if it is an exact match
8+
ALMOST CORRECT, if no more than 2 letters are wrong
9+
WRONG, if more than 2 letters are wrong or if length (correct spelling versus spelling given by contestant) mismatches.
10+
11+
and return a list containing the number of CORRECT answers, number of ALMOST CORRECT answers and number of WRONG answers.
12+
Assume that the words contain only uppercase letters and the maximum word length is 10.
13+
14+
Sample Input
15+
16+
{"THEIR": "THEIR", "BUSINESS": "BISINESS","WINDOWS":"WINDMILL","WERE":"WEAR","SAMPLE":"SAMPLE"}
17+
18+
Expected Output
19+
20+
[2, 2, 1]
21+
'''
22+
23+
#lex_auth_01269444890062848087
24+
25+
def find_correct(word_dict):
26+
#start writing your code here
27+
res=[0,0,0]
28+
for x,y in word_dict.items():
29+
if x == y:
30+
res[0] += 1
31+
elif len(x) == len(y):
32+
count=0
33+
for i in range(len(x)):
34+
if x[i] != y[i]:
35+
count += 1
36+
if count <= 2:
37+
res[1] += 1
38+
else:
39+
res[2] += 1
40+
else:
41+
res[2] += 1
42+
return res
43+
44+
45+
word_dict={"THEIR": "THEIR","BUSINESS":"BISINESS","WINDOWS":"WINDMILL","WERE":"WEAR","SAMPLE":"SAMPLE"}
46+
print(find_correct(word_dict))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /