Five students Adele, Betty,Carol, Doris, and Ellen answered five questions on an exam consisting of two multiplechoice (a,b,c) questions and three trueorfalse questions.
(1) They answered the questions as follows:
I II. III. IV. V
Adele. a a t t t
Betty. b b t f t
Carol. a b t t f
Doris. b c t t f
Ellen. c a f t t
(2) No two students got the same number of correct answers.
Who got the most correct answers?
Doris got the most correct answers.
The correct answers are bctff
The scores are [1, 3, 2, 4, 0]
Doris achieved the highest score of 4

names = ['Adele','Betty','Carol','Doris','Ellen']
students = ['aattt','bbtft','abttf','bcttf','caftt']
answers = []
for v in ['a','b','c']:
for w in ['a','b','c']:
for x in ['t','f']:
for y in ['t','f']:
for z in ['t','f']:
answers.append(v+w+x+y+z)
def matches(r,s):
""" for 2 strings, r and s, how many spots with the same character? """
if len(r) != len(s):
print('not the same length')
return None
same = 0
for i,v in enumerate(r):
if r[i] == s[i]:
same += 1
return same
correctanswers = []
correctscores = []
for answer in answers:
scores = []
for student in students:
scores.append(matches(answer,student))
if len(set(scores)) == 5:
correctanswers.append(answer)
correctscores.append(scores)
if len(correctanswers) == 1:
print('The correct answers are', correctanswers[0])
print('The scores are', correctscores[0])
highestscore = max(correctscores[0])
print( names[ correctscores[0].index(highestscore) ] ,'achieved the highest score of', highestscore )

Posted by Larry
on 20230831 08:47:44 