2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Python]等差数列×等比数列の解を求めてみた[備忘録]

Last updated at Posted at 2021-08-01

はじめに

実装結果を備忘録として残します🐍
Python3環境下にて、是非お使いください🎸

本編

数式

今回コーディングする当差数列×等比数列の数式: \left(an+b \right) \left(c \right)^{\!n} 

コーディング

python
#sympy内の関数を使用
from sympy import *
n=Symbol("n")
a,b,c = map(int,input("a,b,c=? ? ?").split())
while c==0:
    print("Input a,b,c except c=0")
    a,b,c = map(int,input("a,b,c=? ? ?").split())
Prog = sequence((a*n+b)*c**n, (n, 0, 20))

#以下、出力(例:a,b,c=1 1 2)
print([int(N) for N in Prog])
print(Prog[3])

出力結果
[1, 4, 12, 32, 80, 192, 448, 1024, 2304, 5120, 11264, 24576, 53248, 114688, 245760, 524288, 1114112, 2359296, 4980736, 10485760, 22020096]
32

使い方

▶a,b,cは半角スペースで区切り、入力してください。

c=0の場合、while文以下のループが発生します。(c≠0でお願いいたします。)

▶外部ライブラリにつき、予めインストールを要します。(以下、プロンプトでの入力例)

bash/zsh
conda install sympy #エラーが起これば、下のコマンドを実行してください。
pip install sympy 

References

More Info

About me

2
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?