0
0

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のユーザー定義関数「(可変引数関数の改善)引数の個数をn個」をAI先生ヘ。

Posted at

・(可変引数関数の改善)はChatGPT先生のタイトルです。

以下のsympy のソースコードについて
・fun1の引数の個数を任意。n個にしたい。
・ユーザー定義関数の名前をステキな名前にしてほしい。

def fun2(A):
    return print(A,substr(A,1,1),substr(A,2,1)
def fun1(A,B,C):
       fun2(A)
       fun2(B)
       fun2(C)
      return
fun1("1A","2B","3C")

出力
"1A" "1" "A"
"2B" "2" "B"
"3C" "3" "C"

(本日の)ChatGPT先生へ

# 質問リスト
1. fun1の引数の個数を任意。n個にしたい。  
2. ユーザー定義関数の名前をステキな名前にしてほしい。  
3. sympy を使ったバージョンをお願いします。  
4. FreeCAD連携 とは、何か教えて。  
5. 私の質問をMarkdown形式でリスト化して出力して。Markdown形式でリストからアスタリスクは削除して。1行目に、# 質問リスト の文字を出力して。最後の質問も追加して下さい。追番を追加して下さい。

(以下回答抜粋)

以下に、あなたの要望を満たすように修正した sympy ではなく標準的な Python コードを示します:

def print_with_split(string):
    print(string, string[0], string[1])

def majestic_processor(*args):
    for item in args:
        print_with_split(item)

majestic_processor("1A", "2B", "3C", "4D", "5E")

🧠 実装例(sympy 使用)

from sympy import Symbol

def divine_echo(text):
    first, second = text[0], text[1]
    sym1 = Symbol(first)
    sym2 = Symbol(second)
    print(f'"{text}"', sym1, sym2)

def celestial_parser(*args):
    for arg in args:
        divine_echo(arg)

# 実行例
celestial_parser("1A", "2B", "3C")

🧪 さらにできること(発展例)

from sympy import Symbol, Eq, solve

# 例:文字列リストをもとに連立方程式を自動構築(発展応用)
def algebraic_parser(*args):
    equations = []
    for arg in args:
        x = Symbol(arg[0])
        y = Symbol(arg[1])
        eq = Eq(x + y, 10)
        equations.append(eq)
    result = solve(equations)
    print("解:", result)

# algebraic_parser("xA", "yB") などで使えます

・以下省略

Gemini先生へ

copilot先生へ

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

いつもと違うおすすめです。

Qiita内

・いつもお世話になっております。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?