[Python] Sum Σ (sigma) and infinite product Π (pie) were loop statements!

Introduction

This article is a learning note that I noticed while reviewing high school math. Became an engineer while not good at high school math I wrote this because I wanted to convey to someone the small impressions I got while learning from human beings who have moved away from mathematical symbols and mathematical formulas.

Those who want to read this article

I hope it helps the above people.

Sum Σ

\sum_{i=1}^n i

Written in Python, it looks like this.

python


def total(start,end,step):
    temp =0
    for i in range(start,end+1,step):
        temp += i
    return temp

Infinite product Π

\prod_{i=1}^n i

Written in Python, it looks like this.

Infinite product Π


def product(start,end,step):
    temp=start
    for i in range(start,end+1,step):
        temp *= i
    return temp

Recommended Posts

[Python] Sum Σ (sigma) and infinite product Π (pie) were loop statements!
[Python] Notes on while statements (writing style and infinite loop)