-
Notifications
You must be signed in to change notification settings - Fork 0
/
8 kyu Check the exam.py
32 lines (23 loc) · 1.02 KB
/
8 kyu Check the exam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
https://www.codewars.com/kata/5a3dd29055519e23ec000074/train/python
The first input array is the key to the correct answers to an exam, like ["a", "a", "b", "d"]. The second one contains a student's submitted answers.
The two arrays are not empty and are the same length. Return the score for this array of answers, giving +4 for each correct answer, -1 for each incorrect answer, and +0 for each blank answer, represented as an empty string (in C the space character is used).
If the score < 0, return 0.
For example:
checkExam(["a", "a", "b", "b"], ["a", "c", "b", "d"]) → 6
checkExam(["a", "a", "c", "b"], ["a", "a", "b", ""]) → 7
checkExam(["a", "a", "b", "c"], ["a", "a", "b", "c"]) → 16
checkExam(["b", "c", "b", "a"], ["", "a", "a", "c"]) → 0
"""
def check_exam(arr1,arr2):
score = 0
for i,j in zip(arr1, arr2):
if j == '':
score += 0
elif i == j:
score += 4
else:
score -= 1
if score < 0:
return 0
return score