[프로그래머스] 로또의 최고 순위와 최저 순위

eunsiver·2022년 5월 7일
0

코테 with 파이썬

목록 보기
21/21

😂내 코드

def solution(lottos, win_nums):
    answer = []
    win=win_nums
    c=0
    c2=0
    #최고
    for i in range(6):
        if lottos[i] in win_nums:
            c+=1
        if lottos[i]==0:
            c+=1
    #최저
    for i in range(6):
        if lottos[i] in win_nums:
            c2+=1
    a= rank(c)
    b= rank(c2)
    answer=[a,b]
    return answer

def rank(c):
    if c==6: return 1
    elif c==5: return 2
    elif c==4:return 3
    elif c==3: return 4
    elif c==2: return 5
    else: return 6

💥💥매우 심플한 코드

def solution(lottos, win_nums):

    rank=[6,6,5,4,3,2,1]

    cnt_0 = lottos.count(0)
    ans = 0
    for x in win_nums:
        if x in lottos:
            ans += 1
    return rank[cnt_0 + ans],rank[ans]
profile
Let's study!

0개의 댓글

관련 채용 정보