<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python（遊び） | Men of Letters（メン・オブ・レターズ） &#8211; 論理的思考/業務改善/プログラミング</title>
	<atom:link href="https://laboratory.kazuuu.net/category/python%EF%BC%88%E9%81%8A%E3%81%B3%EF%BC%89/feed/" rel="self" type="application/rss+xml" />
	<link>https://laboratory.kazuuu.net</link>
	<description></description>
	<lastBuildDate>Sun, 18 Aug 2024 19:58:40 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://laboratory.kazuuu.net/wp-content/uploads/2021/02/cropped-L-32x32.png</url>
	<title>Python（遊び） | Men of Letters（メン・オブ・レターズ） &#8211; 論理的思考/業務改善/プログラミング</title>
	<link>https://laboratory.kazuuu.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>自由落下とpythonプログラム</title>
		<link>https://laboratory.kazuuu.net/free-fall-and-python-programs/</link>
					<comments>https://laboratory.kazuuu.net/free-fall-and-python-programs/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Sun, 18 Aug 2024 19:58:40 +0000</pubDate>
				<category><![CDATA[Python（遊び）]]></category>
		<category><![CDATA[数学]]></category>
		<category><![CDATA[物理学]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=17679</guid>

					<description><![CDATA[自由落下に関するpythonプログラムを作ってみます。 なお、初速度 v0 が 0 m/s で、地上から自由落下する物体が 10 秒後にどのくらいの速度に達するかを計算し、結果を表示するPythonプログラムを作ります。 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>自由落下に関するpythonプログラムを作ってみます。</p>
<p>なお、初速度 v0 が 0 m/s で、地上から自由落下する物体が 10 秒後にどのくらいの速度に達するかを計算し、結果を表示するPythonプログラムを作ります。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2" checked><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■今回の環境（Python）</a></li><li><a href="#toc2" tabindex="0">■結果を表示するPythonプログラム</a><ol><li><a href="#toc3" tabindex="0">■コード</a></li></ol></li><li><a href="#toc4" tabindex="0">■検証、確認</a></li><li><a href="#toc5" tabindex="0">■補足</a><ol><li><a href="#toc6" tabindex="0">※速度の時間変化をアニメーションとして描画するためのコード</a></li></ol></li></ol>
    </div>
  </div>

<h2><span id="toc1">■今回の環境（Python）</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png"><img decoding="async" class="alignnone size-medium wp-image-17673" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png" alt="" width="300" height="131" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-768x336.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png 865w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonは、バージョン3.10.12を用いる。（なお、Google Colaboratory(Google Colab)を使用。）</p>
<h2><span id="toc2">■結果を表示するPythonプログラム</span></h2>
<h3><span id="toc3">■コード</span></h3>
<pre># 重力加速度 (m/s²)
g = 9.81

# 初速度 (m/s)
v0 = 0

# 時間 (秒)
t = 10

# 速度を計算
v = v0 + g * t

# 結果を表示
print("10 秒後の速度は {:.2f} m/s です。".format(v))</pre>
<h2><span id="toc4">■検証、確認</span></h2>
<p>作成したコードは、Google Colaboratoryの新しいノートブック上のセルにコードを記述します。その後「セルを実行」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-02-132014.png"><img decoding="async" class="alignnone wp-image-17680 size-medium" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-02-132014-300x144.png" alt="" width="300" height="144" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-02-132014-300x144.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-02-132014-1024x493.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-02-132014-768x370.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-02-132014.png 1222w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>先に計算した結果を書くと「98.10 m/s」となります。クリックすると、Google Colaboratory上で処理された結果を確認すると「10 秒後の速度は 98.10 m/s です。」と出力させることができました。</p>
<h2><span id="toc5">■補足</span></h2>
<h3><span id="toc6">※速度の時間変化をアニメーションとして描画するためのコード</span></h3>
<p>import matplotlib.pyplot as plt</p>
<pre>import numpy as np
from matplotlib.animation import FuncAnimation

# 重力加速度 (m/s²)
g = 9.81

# 初速度 (m/s)
v0 = 0

# 時間 (秒)
t = 10

# 時間の配列を作成（0からtまで0.1秒刻み）
time = np.arange(0, t, 0.1)

# 速度の配列を計算
velocity = v0 + g * time

# グラフの初期設定
fig, ax = plt.subplots()
ax.set_xlim(0, t)
ax.set_ylim(0, max(velocity) + 1)
line, = ax.plot([], [], lw=2)

# アニメーションの初期化
def init():
    line.set_data([], [])
    return line,

# アニメーションのフレーム更新
def update(frame):
    x_data = time[:frame]
    y_data = velocity[:frame]
    line.set_data(x_data, y_data)
    return line,

# アニメーションの作成
ani = FuncAnimation(fig, update, frames=len(time), init_func=init, blit=True)

# アニメーションの表示
plt.xlabel('Time (s)')
plt.ylabel('Velocity (m/s)')
plt.title('Velocity vs. Time')
plt.show()</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/free-fall-and-python-programs/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>斜めに投げられた物体とpythonプログラム</title>
		<link>https://laboratory.kazuuu.net/object-thrown-at-an-angle-and-python-program/</link>
					<comments>https://laboratory.kazuuu.net/object-thrown-at-an-angle-and-python-program/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Fri, 09 Aug 2024 19:13:18 +0000</pubDate>
				<category><![CDATA[Python（遊び）]]></category>
		<category><![CDATA[数学]]></category>
		<category><![CDATA[物理学]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=17683</guid>

					<description><![CDATA[斜めに投げられた物体に関するpythonプログラムを作ってみます。 物体が斜めに投げられる場合、水平方向と鉛直方向の速度が影響します。水平方向の速度を Vx ​ 、鉛直方向の速度を Vy ​ とし、初速度 V0 ​ の物 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>斜めに投げられた物体に関するpythonプログラムを作ってみます。</p>
<p>物体が斜めに投げられる場合、水平方向と鉛直方向の速度が影響します。水平方向の速度を Vx ​ 、鉛直方向の速度を Vy ​ とし、初速度 V0 ​ の物体が角度 θ で斜めに投げられるとします。以下の式を使用して、物体の位置を時間と共に計算します。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-141738.png"><img decoding="async" class="alignnone size-full wp-image-17684" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-141738.png" alt="" width="394" height="115" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-141738.png 394w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-141738-300x88.png 300w" sizes="(max-width: 394px) 100vw, 394px" /></a></p>
<p>ここで、x は水平方向の位置（メートル）、 y は鉛直方向の位置（メートル）、 t は時間（秒）です。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-4" checked><label class="toc-title" for="toc-checkbox-4">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■今回の環境（Python）</a></li><li><a href="#toc2" tabindex="0">■斜めに投げられた物体に関するpythonプログラム</a><ol><li><a href="#toc3" tabindex="0">■コード</a></li><li><a href="#toc4" tabindex="0">■検証、確認</a></li></ol></li></ol>
    </div>
  </div>

<h2><span id="toc1">■今回の環境（Python）</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-17673" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png" alt="" width="300" height="131" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-768x336.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png 865w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonは、バージョン3.10.12を用いる。（なお、Google Colaboratory(Google Colab)を使用。）</p>
<h2><span id="toc2">■斜めに投げられた物体に関するpythonプログラム</span></h2>
<p>今回は初速度 <span class="math math-inline"><span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="mord"><span class="mord mathnormal">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist"><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span><span class="vlist-s">​</span></span></span></span></span><span class="mrel">=</span></span><span class="base"><span class="mord">20</span></span></span></span></span> m/s で、角度 <span class="math math-inline"><span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="mord mathnormal">θ</span><span class="mrel">=</span></span><span class="base"><span class="mord">3</span><span class="mord">0<span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist"><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∘</span></span></span></span></span></span></span></span></span></span></span> で斜めに投げられた物体の高度を時間と共に計算し、0 になる時間を求めるプログラムを作ってみます。プログラムを実行後、物体が地上に戻る時間を計算します。</p>
<h3><span id="toc3">■コード</span></h3>
<pre>import math

# 初速度 (m/s)
v0 = 20

# 投げる角度 (度)
theta = 30

# 重力加速度 (m/s²)
g = 9.81

# 角度をラジアンに変換
theta = math.radians(theta)

# 初速度を水平方向と鉛直方向の速度に分解
vx = v0 * math.cos(theta)
vy = v0 * math.sin(theta)

# 物体が地上に戻る時間を計算
t = (2 * vy) / g

# 結果を表示
print("物体が地上に戻る時間は {:.2f} 秒です。".format(t))</pre>
<h3><span id="toc4">■検証、確認</span></h3>
<p>作成したコードは、Google Colaboratoryの新しいノートブック上のセルにコードを記述します。その後「セルを実行」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-143003.png"><img loading="lazy" decoding="async" class="alignnone wp-image-17688 size-medium" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-143003-300x202.png" alt="" width="300" height="202" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-143003-300x202.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-143003-1024x688.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-143003-768x516.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-06-143003.png 1027w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>先に答えを書くと「2.04 秒」となります。クリック後、Google Colaboratory上で処理された計算結果を確認すると「物体が地上に戻る時間は 2.04 秒です。」と出力させることができました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/object-thrown-at-an-angle-and-python-program/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pythonを使用した簡単な代数の問題を解く</title>
		<link>https://laboratory.kazuuu.net/solve-simple-algebra-problems-using-python/</link>
					<comments>https://laboratory.kazuuu.net/solve-simple-algebra-problems-using-python/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Fri, 09 Aug 2024 04:32:40 +0000</pubDate>
				<category><![CDATA[Python（遊び）]]></category>
		<category><![CDATA[数学]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=17676</guid>

					<description><![CDATA[Pythonを使用した簡単な代数の問題を解くことについて解説します。 今回は代数方程式を解くためにSymPyを使用します。Google ColaboratoryではSympyがすでにインストールされた状態となっています。 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Pythonを使用した簡単な代数の問題を解くことについて解説します。</p>
<p>今回は代数方程式を解くためにSymPyを使用します。Google ColaboratoryではSympyがすでにインストールされた状態となっています。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-6" checked><label class="toc-title" for="toc-checkbox-6">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■今回の環境（Python）</a></li><li><a href="#toc2" tabindex="0">■簡単な代数の問題を解く</a><ol><li><a href="#toc3" tabindex="0">■コード</a></li></ol></li><li><a href="#toc4" tabindex="0">■検証、確認</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">■今回の環境（Python）</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-17673" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png" alt="" width="300" height="131" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-768x336.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png 865w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonは、バージョン3.10.12を用いる。（なお、Google Colaboratory(Google Colab)を使用。）</p>
<h2><span id="toc2">■簡単な代数の問題を解く</span></h2>
<p>以下の代数方程式を解く</p>
<pre>3x−5=10</pre>
<h3><span id="toc3">■コード</span></h3>
<pre>import sympy as sp

# 未知数を定義
x = sp.symbols('x')

# 代数方程式を定義
equation = 3*x - 5 - 10

# 方程式を解く
solution = sp.solve(equation, x)

print("方程式の解は x =", solution[0])</pre>
<h2><span id="toc4">■検証、確認</span></h2>
<p>作成したコードは、Google Colaboratoryの新しいノートブック上のセルにコードを記述します。その後「セルを実行」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-01-150725.png"><img loading="lazy" decoding="async" class="alignnone wp-image-17677 size-medium" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-01-150725-300x141.png" alt="" width="300" height="141" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-01-150725-300x141.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-01-150725-1024x483.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-01-150725-768x362.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/11/スクリーンショット-2023-11-01-150725.png 1249w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、代数方程式の答えは「x=5」となりますので、Google Colaboratory上で処理された結果を確認すると「方程式の解は x = 5」と出力されていますので、代数の問題を解くことができました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/solve-simple-algebra-problems-using-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>フィボナッチ数列を使って三角形を出力するPythonコード</title>
		<link>https://laboratory.kazuuu.net/python-code-to-output-a-triangle-using-the-fibonacci-sequence/</link>
					<comments>https://laboratory.kazuuu.net/python-code-to-output-a-triangle-using-the-fibonacci-sequence/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Wed, 07 Aug 2024 19:30:52 +0000</pubDate>
				<category><![CDATA[Python（遊び）]]></category>
		<category><![CDATA[数学]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=17672</guid>

					<description><![CDATA[今回は、フィボナッチ数列を使って三角形を出力するPythonコードを作ってみます。 目次 ■今回の環境（Python）■フィボナッチ数列を使って三角形を出力する■検証、確認 ■今回の環境（Python） 今回のPytho [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>今回は、フィボナッチ数列を使って三角形を出力するPythonコードを作ってみます。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-8" checked><label class="toc-title" for="toc-checkbox-8">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■今回の環境（Python）</a></li><li><a href="#toc2" tabindex="0">■フィボナッチ数列を使って三角形を出力する</a></li><li><a href="#toc3" tabindex="0">■検証、確認</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">■今回の環境（Python）</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-17673" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png" alt="" width="300" height="131" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-300x131.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813-768x336.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-134813.png 865w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonは、バージョン3.10.12を用いる。（なお、Google Colaboratory(Google Colab)を使用。）</p>
<h2><span id="toc2">■フィボナッチ数列を使って三角形を出力する</span></h2>
<p>では、フィボナッチ数列を使って三角形を出力するPythonコードを書いていきます。</p>
<pre>def generate_fibonacci_triangle(rows):
    fibonacci_numbers = [1, 1]
    fibonacci_triangle = [[1], [1, 1]]

    for n in range(2, rows):
        fibonacci_n = fibonacci_numbers[n - 1] + fibonacci_numbers[n - 2]
        fibonacci_numbers.append(fibonacci_n)

        row = [1]
        for i in range(1, n):
            row.append(fibonacci_numbers[i])
        fibonacci_triangle.append(row)

    return fibonacci_triangle

def print_fibonacci_triangle(triangle):
    max_width = len(' '.join(map(str, triangle[-1])))

    for row in triangle:
        row_str = ' '.join(map(str, row))
        print(row_str.center(max_width))

if __name__ == "__main__":
    num_rows = 15  # 任意の行数を指定できます
    triangle = generate_fibonacci_triangle(num_rows)
    print_fibonacci_triangle(triangle)</pre>
<p>このコードでは、指定した行数（num_rows）のフィボナッチ数列の三角形を生成し、それを表示します。print_fibonacci_triangle関数は、各行の要素を適切に中央揃えして表示します。必要に応じて、num_rowsを調整して三角形の高さを変更できます。</p>
<h2><span id="toc3">■検証、確認</span></h2>
<p>作成したコードは、Google Colaboratoryの新しいノートブック上のセルにコードを記述します。その後「セルを実行」ボタンをクリックします。</p>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-135426.png"><img loading="lazy" decoding="async" class="alignnone wp-image-17674 size-medium" src="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-135426-300x200.png" alt="" width="300" height="200" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-135426-300x200.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-135426-1024x683.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-135426-768x512.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2023/10/スクリーンショット-2023-10-30-135426.png 1129w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>クリックすると、セル上のコードが読み込まれ処理が実行となり、出力が表示されます。出力結果を確認すると、フィボナッチ数列を使って三角形を出力することができました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/python-code-to-output-a-triangle-using-the-fibonacci-sequence/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pythonでmtgsdkを用いて「神河:輝ける世界」の特定カードを出力する</title>
		<link>https://laboratory.kazuuu.net/output-specific-cards-for-kamigawa-using-mtgsdk-in-python/</link>
					<comments>https://laboratory.kazuuu.net/output-specific-cards-for-kamigawa-using-mtgsdk-in-python/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Tue, 15 Mar 2022 21:00:15 +0000</pubDate>
				<category><![CDATA[Python（遊び）]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=11817</guid>

					<description><![CDATA[Pythonでmtgsdkを用いて「神河:輝ける世界」の特定カードを出力してみます。 今回は、mtgsdkを用います。mtgsdkはPythonの標準ライブラリ・モジュールではないので、事前にインストールする必要がありま [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Pythonでmtgsdkを用いて「神河:輝ける世界」の特定カードを出力してみます。</p>
<p>今回は、mtgsdkを用います。mtgsdkはPythonの標準ライブラリ・モジュールではないので、<a href="https://laboratory.kazuuu.net/installation-of-mtgsdk-python-wrapper-for-mtg-api">事前にインストールする必要</a>があります。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-10" checked><label class="toc-title" for="toc-checkbox-10">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■Python</a></li><li><a href="#toc2" tabindex="0">■mtgsdkを用いて「神河:輝ける世界」の特定カードを出力する</a><ol><li><a href="#toc3" tabindex="0">■コード</a></li></ol></li><li><a href="#toc4" tabindex="0">■実行・検証</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">■Python</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-8343" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png" alt="" width="300" height="197" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-1024x671.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-768x503.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonのバージョンは、「3.8.5」を使用しています。（Windows10）（pythonランチャーでの確認）</p>
<h2><span id="toc2">■mtgsdkを用いて「神河:輝ける世界」の特定カードを出力する</span></h2>
<p>では、早速mtgsdkを用いて「神河:輝ける世界」の特定カードを出力するスクリプトを書いていきます。</p>
<h3><span id="toc3">■コード</span></h3>
<pre>from mtgsdk import Card

cards = Card.where(language="Japanese").where(set='neo').all()

print(cards[0].name)</pre>
<p>「from import」でmtgsdkのCardを呼び出します。その後、cardsという変数を定義し、その中で、Cardに対してwhere()を用います。括弧内には「language=&#8221;Japanese&#8221;」と記述し、今回は日本語からカードを入手します。次に「set=&#8217;neo&#8217;」と記述し、エキスパンション「神河:輝ける世界」の略称である「neo」を設定します。あとは、エキスパンション「神河:輝ける世界」のカードのリストを全て取得するために、all()を用います。これでエキスパンション「神河:輝ける世界」のデータがcards変数に格納されます。</p>
<p>最後に、cards変数に格納された情報（リスト）の番号「0」のカード名（タイトル）をprint()を用いて出力してみます。</p>
<h2><span id="toc4">■実行・検証</span></h2>
<p>このスクリプトを「mtg_test.py」という名前で、Pythonが実行されている作業ディレクトリ（カレントディレクトリ）に保存し、コマンドプロンプトから実行してみます。</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-11819" src="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-13-134521-1-300x172.png" alt="" width="300" height="172" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-13-134521-1-300x172.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-13-134521-1-1024x587.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-13-134521-1-768x441.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-13-134521-1-120x68.png 120w, https://laboratory.kazuuu.net/wp-content/uploads/2022/03/スクリーンショット-2022-03-13-134521-1.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>実行してみると、「Ancestral Katana（祖先の刀）」が出力されることを確認しました。「Ancestral Katana（祖先の刀）」は、エキスパンション「神河:輝ける世界」のリストでは「1」となっているものです。</p>
<p>今回、mtgsdkを用いてみましたが、Python 3.4で開発されていましたが「3.8.5」であっても、一応、動作することがわかりました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/output-specific-cards-for-kamigawa-using-mtgsdk-in-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MTG（マジック:ザ・ギャザリング）APIのPythonラッパー「mtgsdk」のインストール</title>
		<link>https://laboratory.kazuuu.net/installation-of-mtgsdk-python-wrapper-for-mtg-api/</link>
					<comments>https://laboratory.kazuuu.net/installation-of-mtgsdk-python-wrapper-for-mtg-api/#respond</comments>
		
		<dc:creator><![CDATA[小林]]></dc:creator>
		<pubDate>Mon, 14 Mar 2022 21:01:29 +0000</pubDate>
				<category><![CDATA[Python（遊び）]]></category>
		<guid isPermaLink="false">https://laboratory.kazuuu.net/?p=11815</guid>

					<description><![CDATA[MTG（マジック:ザ・ギャザリング）APIのPythonラッパー「mtgsdk」のインストールについて解説しています。 「mtgsdk（https://github.com/MagicTheGathering/mtg-s [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>MTG（マジック:ザ・ギャザリング）APIのPythonラッパー「mtgsdk」のインストールについて解説しています。</p>
<p>「mtgsdk（<a href="https://github.com/MagicTheGathering/mtg-sdk-python">https://github.com/MagicTheGathering/mtg-sdk-python</a>）」は、マジック：ザ・ギャザリングの開発者向けリソース（<a href="https://magicthegathering.io/">https://magicthegathering.io/</a>）のMTG APIのラッパーです。</p>

  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-12" checked><label class="toc-title" for="toc-checkbox-12">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">■Python</a></li><li><a href="#toc2" tabindex="0">■mtgsdkをインストールする</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">■Python</span></h2>
<p><a href="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png"><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-8343" src="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png" alt="" width="300" height="197" srcset="https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-300x197.png 300w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-1024x671.png 1024w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949-768x503.png 768w, https://laboratory.kazuuu.net/wp-content/uploads/2021/05/スクリーンショット-2021-05-15-072949.png 1250w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>今回のPythonのバージョンは、「3.8.5」を使用しています。（Windows10）（pythonランチャーでの確認）</p>
<p>なお、この「mtgsdk」パッケージはPython 3.4 で開発されていますが、今回は「3.8.5」にインストールを試みます。</p>
<h2><span id="toc2">■mtgsdkをインストールする</span></h2>
<p>mtgsdkをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。</p>
<pre>pip install mtgsdk</pre>
<p>起動後、上記のコマンドを入力し、Enterキーを押します。</p>
<p>なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、pipを使う場合にはコマンドでの切り替えを行います。</p>
<pre>py -3.8 -m pip install mtgsdk</pre>
<p>切り替えるために、上記のコマンドを入力し、Enterキーを押します。</p>
<pre>Defaulting to user installation because normal site-packages is not writeable
Collecting mtgsdk
Downloading mtgsdk-1.3.1.tar.gz (6.1 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: mtgsdk
Building wheel for mtgsdk (setup.py) ... done
Created wheel for mtgsdk: filename=mtgsdk-1.3.1-py3-none-any.whl size=13918 sha256=c27eaeffe23e9f8621ec51fb6d5fafd2608b4c17e7bb87245239e3aab9cc63b9
Stored in directory: c:\users\user_\appdata\local\pip\cache\wheels\ea\fb\97\3e88a1120515cccae937bb7b44064c8a8fad21f1a99a2a490b
Successfully built mtgsdk
Installing collected packages: mtgsdk
Successfully installed mtgsdk-1.3.1</pre>
<p>Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、mtgsdkが正常にインストールされたことになります。</p>
<p>なお、今回はmtgsdkのバージョン1.3.1をインストールしました。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://laboratory.kazuuu.net/installation-of-mtgsdk-python-wrapper-for-mtg-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
