honey_pot
[python] 로또의 최고 순위와 최저 순위 본문
https://programmers.co.kr/learn/courses/30/lessons/77484#
def solution(lottos, win_nums):
answer = []
match = 0
zero = lottos.count(0)
for i in lottos:
if i in win_nums:
match += 1
if match==0 and zero==0:
answer.append(6)
else:
answer.append(6-(zero+match)+1)
if match == 0 :
answer.append(6)
else:
answer.append(6-match+1)
return answer
최고순위는 6-0의 개수-맞는 번호 +1
최저순위는 6 - 맞는 번호 +1
match와 zero 가 하나도 없을 경우, match만 없는 경우를 if 문으로 조건을 주고 출력했다.
다른 방법으로 아예 순위를 리스트에 넣고 인덱스로 순위를 뽑는 방법이 있던데 이게 더 직관적이고 편한것같다.
def solution(lottos,win_nums):
answer = [0,0]
rank = [6,65,4,3,2,1]
cnt =0
zero = lottos.count(0)
for i in lottos:
if i in win_nums:
cnt += 1
answer[0],answer[1] = rank[cnt+ zero], rank[cnt]
return answer
'문제 풀이' 카테고리의 다른 글
[python] 체육복 (0) | 2021.09.09 |
---|---|
[python] 크레인 인형뽑기 게임 (0) | 2021.09.09 |
[python] 비밀지도 (0) | 2021.09.09 |
[python] 폰켓몬 (0) | 2021.09.08 |
[python] 키패드 누르기 (0) | 2021.09.02 |
Comments