def f(x):
return 2 * x + 1
print(f(10))
def f(x):
return x ** 2 + 2 * x + 1
print(f(10))
def mul(*values):
result = 1
for value in values:
result *= value
return result
print(mul(5, 7, 9, 10))
def function(*values, valueA, valueB):
pass
function(1, 2, 3, 4, 5)
TypeError: function() missing 2 required keyword-only arguments: 'valueA' and 'valueB'
min = 2
max = 10
person = 100
memo = dict()
def table(remain, current):
key = str([remain, current])
if (key in memo):
return memo[key]
if (remain < 0):
return 0
if (remain == 0):
return 1
total = 0
for case in range(current, max + 1):
total += table(remain - case, case)
memo[key] = total
return total
print(table(person, min))
numbers = [1, 2, 3, 4, 5, 6]
print("::".join(str(number) for number in numbers))
numbers = list(range(1, 10 + 1))
print("# 홀수만 추출하기")
print(list(filter(lambda number: number % 2 == 1, numbers)))
print()
print("# 3 이상, 7 미만 추출하기")
print(list(filter(lambda number: number >= 3 and number < 7, numbers)))
print()
print("# 제곱해서 50 미만 추출하기")
print(list(filter(lambda number: number ** 2 < 50, numbers)))
num_of_disc = 3
print(f"원판의 개수 {num_of_disc}")
def hanoi(disc, start, end, between):
if (disc < 1):
return 0
if (disc == 1):
print(f"{start} -> {end}")
return 1
value = hanoi(disc - 1, start, between, end)
print(f"{start} -> {end}")
value += hanoi(disc - 1, between, end, start)
return value + 1
print("이동 횟수: ", hanoi(num_of_disc, 'A', 'C', 'B'))