Guidelines

λžŒλ‹€λ‘œ ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄ κ³„μ‚°ν•˜κΈ°

λžŒλ‹€ ν•¨μˆ˜λ₯Ό μ΄μš©ν•΄ ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄(ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄μ€ 이전 두 수의 합이 λ‹€μŒ μˆ˜κ°€ λ˜λŠ” μˆ˜μ—΄)을 계산할 수 μžˆμŠ΅λ‹ˆλ‹€.


λžŒλ‹€ ν•¨μˆ˜μ˜ μ‚¬μš©

ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄μ„ κ³„μ‚°ν•˜κΈ° μœ„ν•΄ lambda ν‚€μ›Œλ“œλ‘œ μž¬κ·€μ μœΌλ‘œ μ •μ˜λœ 읡λͺ… ν•¨μˆ˜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.

λžŒλ‹€ ν•¨μˆ˜λ₯Ό μ΄μš©ν•œ ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄ ν•¨μˆ˜
fib = lambda x: x if x <= 1 else fib(x-1) + fib(x-2) # ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄ lambda ν•¨μˆ˜ μ •μ˜ # ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄μ˜ 5번째 ν•­ 계산 print(fib(5)) # 5 # ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄μ˜ 10번째 ν•­ 계산 print(fib(10)) # 55

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result