Python問題ライブラリ(コード作成)#25-28

9546 ワード

25.探索バイナリ


26.統計学

import statistics

n = int(input("몇 개의 수를 입력하시겠습니까? :"))
list = []

for i in range(n):
    list.append(int(input()))

#산술평균
def mean(list):
    mean=sum(list)/len(list)
    print("산술평균: {0}".format(mean))

#중앙값
def median(list):
    list = sorted(list)
    median = list[len(list)//2]
    print("중앙값: {0}".format(median))

#최빈값
def count(list):
    print(statistics.mode(list))

#범위
def range(list):
    mins = min(list)
    maxs = max(list)
    range = maxs - mins
    print("범위: {0}".format(range))



mean(list)
median(list)
count(list)
range(list)

###최빈값 모르겠다....
###최빈값 모르겠다....
###최빈값 모르겠다....
###최빈값 모르겠다....
###최빈값 모르겠다....

27.ブラックジャック

n, x = map(int,input("카드개수, 목표값 입력:").split())
card = list(map(int,input("").split()))
total_lst = []

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            total = card[i] + card[j] + card[k]
            if total <= x:
                total_lst.append(total)

print(max(total_lst))

ドラゴンを引き継ぐ