Help us understand the problem. What is going on with this article?

二項定理をpythonで計算する

More than 1 year has passed since last update.

二項定理の定義

二項定理とは,

初等代数学における二項定理(にこうていり、英: binomial theorem)または二項展開 (binomial expansion) は二項式の冪の代数的な展開を記述するものである。定理によれば、冪 (x + y)n は a xb yc の形の項の和に展開できる。ただし、冪指数 b, c は b + c = n を満たす非負整数で、各項の係数 a は n と b に依存して決まる特定の正整数である。

Wikipediaより

あっ…

Pythonに計算させよう

BinomialTheorem.py
from math import *

def calc(k):
    return [ factorial(k)/(factorial(i)*factorial(k-i)) for i in range(k+1)]

これを使うと,

>>> calc(0)
[1]

>>> calc(6)
[1, 6, 15, 20, 15, 6, 1]

>>> calc(12)
[1, 12, 66, 220, 495, 792, 924, 792, 495, 220, 66, 12, 1]

こんな感じでlist型で返してくれる.

2018/10/25訂正
関数calc内で結果をreturnしてませんでした.
@shiracamus さん,ご指摘いただきありがとうございます.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした