목록Python Algorithm (133)
cool hamsters never sleep
딕셔너리로 푸는 문제! score = {'A+': 4.3, 'A0': 4.0, 'A-': 3.7, 'B+': 3.3, 'B0': 3.0, 'B-': 2.7, 'C+': 2.3, 'C0': 2.0, 'C-': 1.7, 'D+': 1.3, 'D0': 1.0, 'D-': 0.7, 'F': 0.0} print(score[str(input())]) 아래는 틀린 코드인데 결과값이 숫자가 아닌 글자로 출력되서 그런듯 score = {'A+' : '4.3', 'A0' : '4.O', 'A-' : '3.7', 'B+' : '3.3', 'B0' : '3.0', 'B-' : '2.7', 'C+' : '2.3', 'C0' : '2.0', 'C-' : '1.7', 'D+' : '1.3', 'D0' : '1.0', 'D-' : ..
w = list(input()) s = list(reversed(w)) if w == s : print(1) else : print(0) 처음에 sorted(리스트 명, reverse = True)를 사용하려 했으나 이 경우에 아예 정렬을 하므로 단순 뒤집기가 아니게 되버림 따라서 reversed()로 단순 뒤집기만 함 아래는 abba 를 입력했을 때의 반례가 존재하는 잘못된 코드 w = list(input()) s = sorted(w, reverse = True) x = 0 for i in range (len(w)) : if w[i] == s[i] : x = x + 1 if x == len(w) : print(1) else : print(0)
s = [] for i in range (int(input())) : s.append(int(input())) if s.count(1) < s.count(0) : print("Junhee is not cute!") else : print("Junhee is cute!")
v = int(input()) sco = list(input()) if sco.count("A") > sco.count("B") : print("A") elif sco.count("A") < sco.count("B") : print("B") else : print("Tie")
for i in range (int(input())) : k = int(input()) n = int(input()) zerofloor = [i for i in range (1, n+1)] # 0층의 1호부터 입력받은 n호까지 인원 수 생성 for i in range(k) : # 층 만큼 반복 for j in range (1, n) : # 호 만큼 반복 (인덱스 0은 1호이고, 항상 1이므로 제외) zerofloor[j] = zerofloor[j] + zerofloor[j-1] print(zerofloor[n-1]) list comprehension [할당되는 변수 for 사용할 변수 이름 in 범위]