模擬試験
質問する
私の答え(正しい)
def solution(answers):
answer = []
fs = [1,2,3,4,5]
ss = [2,1,2,3,2,4,2,5]
ts = [3,3,1,1,2,2,4,4,5,5]
fs_score = 0
ss_score = 0
ts_score = 0
for number in range(len(answers)):
if answers[number] == fs[number%5]:
fs_score += 1
if answers[number] == ss[number%8]:
ss_score += 1
if answers[number] == ts[number%10]:
ts_score += 1
std_scores = [fs_score, ss_score, ts_score]
for i, score in enumerate(std_scores):
if score == max(std_scores):
answer.append(i+1)
return answer
列挙注意:wikidocs
tuple
の形式で、>>> t = [1, 5, 7, 33, 39, 52]
>>> for p in enumerate(t):
... print(p)
...
(0, 1)
(1, 5)
(2, 7)
(3, 33)
(4, 39)
(5, 52)
>>> for i, v in enumerate(t):
... print("index : {}, value: {}".format(i,v))
...
index : 0, value: 1
index : 1, value: 5
index : 2, value: 7
index : 3, value: 33
index : 4, value: 39
index : 5, value: 52
最も高い割合の解答
def solution(answers):
pattern1 = [1,2,3,4,5]
pattern2 = [2,1,2,3,2,4,2,5]
pattern3 = [3,3,1,1,2,2,4,4,5,5]
score = [0, 0, 0]
result = []
for idx, answer in enumerate(answers):
if answer == pattern1[idx%len(pattern1)]:
score[0] += 1
if answer == pattern2[idx%len(pattern2)]:
score[1] += 1
if answer == pattern3[idx%len(pattern3)]:
score[2] += 1
for idx, s in enumerate(score):
if s == max(score):
result.append(idx+1)
return result
score
のリストに載っていて、コードを簡潔にする様子Reference
この問題について(模擬試験), 我々は、より多くの情報をここで見つけました https://velog.io/@hiyee-gj/005.-모의고사テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol