プログラム出力は次の効果を達成する必要があります:
[1] [1,1] [1,2,1] [1,3,3,1]
......
メソッド:反復、ジェネレーター
def triangles() L = [1] while True: yiled L L =[1] + [L[i] + L[I+1] for i in range(len(L)-1)] + [1] n = 0 for t in triangles(): print(t) n += 1 if n == 10: break
実装ロジック:
1. yield がジェネレーターの出力を中断するため、最初の出力は[1]
2. while以下のyield以降のループを継続します。このときリストの長さは1です。これをLのlen(L)に代入して[L[i]+L[i+1]を取得します。 ] for i in range(1-1)] の結果はnull値となるため、yield Lの出力は[1,1]
3となります。このとき、len(L)の値は2となり、代入結果はin [L[i]+L [i+1] for i in range(2-1)] は [L[i]+L[i+1] for i in range(1)]、i は値を取得できます0、置換後は [L[0]+L[1]] となり、L[0] と L[1] の値は両方とも 1 になります (上記の結果からわかるように)。出力結果は [1,2,1]
4. 3 番目の記事より このとき len(L) の値は 3 であることがわかります。代入すると [L[i]+L[i+] になります。 1] for i in range(2)] i の値は 0 と 1 です。ループを通じて出力される値は 2 つあり、どちらも [L[0]+L[1]] で表されます。 、[L[1]+L[2]]
以上がYang Hui の Python によるトライアングルメソッドの紹介例の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond

pythonisnotpurelyLepted; itusesahybridapproachofbytecodecodecodecodecodecodedruntimerttation.1)pythoncompilessourcodeintobytecode、whodythepythonvirtualmachine(pvm).2)

ToconcatenateListsinpythothesheElements、使用:1)Operatortokeepduplicates、2)asettoremoveduplicates、or3)listcomplunting for controloverduplicates、各メトドハスディフェルフェルフェントパフォーマンスアンドソーダーインプリテーション。

pythonisantertedlanguage、useaseofuseandflexibility-butfactingporformantationationsincriticalapplications.1)解釈されたlikepythonexecuteline-by-lineを解釈します

Useforloopswhenthenumberofiterationsisknowninadvance、andwhiloopswheniterationsdependonacondition.1)forloopsareidealforsecenceslikelistoranges.2)


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。
