<?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>新手教學 &#8211; 龍冥 Blog</title>
	<atom:link href="https://dragongo.co/tag/%e6%96%b0%e6%89%8b%e6%95%99%e5%ad%b8/feed/" rel="self" type="application/rss+xml" />
	<link>https://dragongo.co</link>
	<description>Code &#38; Read</description>
	<lastBuildDate>Mon, 18 Aug 2025 14:52:14 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>

<image>
	<url>https://dragongo.co/wp-content/uploads/2021/05/cropped-cropped-LOGO-2-e1655437907165-32x32.png</url>
	<title>新手教學 &#8211; 龍冥 Blog</title>
	<link>https://dragongo.co</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>[Python入門教學] if, elif, else 是什麼?</title>
		<link>https://dragongo.co/python%e5%85%a5%e9%96%80%e6%95%99%e5%ad%b8-if-elif-else-%e6%98%af%e4%bb%80%e9%ba%bc/</link>
		
		<dc:creator><![CDATA[龍冥]]></dc:creator>
		<pubDate>Mon, 18 Aug 2025 14:49:58 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[新手教學]]></category>
		<guid isPermaLink="false">https://dragongo.co/?p=2443</guid>

					<description><![CDATA[記錄一下這次上課的內容，供上課的夥伴或補課的夥伴&#8230;]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="2443" class="elementor elementor-2443">
						<section class="penci-section penci-disSticky penci-structure-10 elementor-section elementor-top-section elementor-element elementor-element-e48df61 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="e48df61" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="penci-ercol-100 penci-ercol-order-1 penci-sticky-ct    elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ea3f5c2" data-id="ea3f5c2" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-0849ca1 elementor-widget elementor-widget-text-editor" data-id="0849ca1" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>記錄一下這次上課的內容，供上課的夥伴或補課的夥伴做複習使用。這次上課主要是針對布林資料型態還有 if else 來做一個範例程式。</p><p>首先講一下這個範例程式大概在做的功能。它會先問使用者分數，當你輸入分數進去之後，它會顯示布林值，判斷這個分數是否大於等於60。如果大於等於60，它就會顯示及格；如果小於60，它就會顯示不及格，並 print 不及格的部分。</p><p>這邊有幾個要注意的點：<br />第一個是 if 和 else，當 if 和 else 出現時，它們是在 python 裡面保留的關鍵字，是專門用來做指令的。後面會用一個條件句，如 score 大於等於60，然後冒號後面的下一行是要執行的命令，如果今天我的指令要包在 if 條件句裡面，就需要在下一行的指令中縮排。比較推薦用 tab 鍵快速縮排，再透過 shift 加 tab 鍵快捷鍵減少縮排。不建議用空白鍵和刪除鍵，因為空白鍵難以判斷縮排的間隔是否正確。</p>								</div>
				</div>
				<div class="elementor-element elementor-element-e3dc87c elementor-widget elementor-widget-code-block-for-elementor" data-id="e3dc87c" data-element_type="widget" data-e-type="widget" data-widget_type="code-block-for-elementor.default">
				<div class="elementor-widget-container">
					<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-python'>#bool Boolean 布林 -&gt; 是/否 True/False

score = int(input(&quot;分數？&quot;))

# 先看bool result結果
# score &gt;= 60 scroe有沒有大於等於60?

print(&quot;boolean：&quot;, score &gt;= 60)

# 再轉成人類可讀
if score &gt;= 60: #如果score有沒有大於等於60: 做以下的事情
  print(&quot;及格！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f389.png" alt="🎉" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)
else: #否則: 做以下的事情
  print(&quot;不及格，要加油！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4aa.png" alt="💪" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)

#快速縮排：tab 減少縮排shift+tab
# 不要用空白鍵，你會有一堆bug要除</code></pre>				</div>
				</div>
				<div class="elementor-element elementor-element-ac15126 elementor-widget elementor-widget-text-editor" data-id="ac15126" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><span style="color: inherit; font-family: inherit; font-size: inherit; font-weight: inherit; text-align: inherit;">第二部分是防止使用者輸入空白鍵。我們用 if else 的方式來做，將使用者輸入的文字透過 if 條件句判斷是否有數值。如果有數值，if 條件句為 true；如果沒有輸入任何資訊，就會進入 else，提示使用者不要輸入空白。</span></p><p>在判斷完使用者有沒有輸入分數之後，再透過 int 指令將原本輸入進來的文字轉換成整數型態，再做後續的 if else 判斷。同樣地，如果 score 大於等於60 就顯示及格，否則顯示不及格。</p>								</div>
				</div>
				<div class="elementor-element elementor-element-817b94a elementor-widget elementor-widget-code-block-for-elementor" data-id="817b94a" data-element_type="widget" data-e-type="widget" data-widget_type="code-block-for-elementor.default">
				<div class="elementor-widget-container">
					<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-python'>#防止使用者輸入空白鍵
score_input = input(&quot;分數？&quot;)
if score_input: #user有無輸入分數?

  score = int(score_input) #轉成整數

  print(&quot;boolean：&quot;, score &gt;= 60)
  if score &gt;= 60: #如果score有沒有大於等於60: 做以下的事情
    print(&quot;及格！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f389.png" alt="🎉" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)
  else: #否則: 做以下的事情
    print(&quot;不及格，要加油！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4aa.png" alt="💪" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)
</code></pre>				</div>
				</div>
				<div class="elementor-element elementor-element-5453af8 elementor-widget elementor-widget-text-editor" data-id="5453af8" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p style="font-size: 14px; text-align: start; font-family: Roboto, sans-serif; font-weight: 400; color: rgb(0, 0, 0);">進階版，我示範了一個 try except 寫法。這段程式碼主要用常見的 try except 寫法防止使用者輸入非預期資訊時，可以提醒使用者輸入正確數字或通知發生未知錯誤。這部分比較屬於進階內容，在這篇文章中不多贅述，只是 demo 一下這樣的程式碼可以減少看到程式 error 的機會，又能正確收到提示。</p>								</div>
				</div>
				<div class="elementor-element elementor-element-4311908 elementor-widget elementor-widget-code-block-for-elementor" data-id="4311908" data-element_type="widget" data-e-type="widget" data-widget_type="code-block-for-elementor.default">
				<div class="elementor-widget-container">
					<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-python'>try:
  score_input = input(&quot;分數？&quot;)
  score = int(score_input) #轉成整數
  print(&quot;boolean：&quot;, score &gt;= 60)
  if not 0 &lt;score &lt; 100:
    raise ValueError(&quot;請輸入0~100的數字&quot;)

  if score &gt;= 60: #如果score有沒有大於等於60: 做以下的事情
    print(&quot;及格！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f389.png" alt="🎉" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)
  else: #否則: 做以下的事情
    print(&quot;不及格，要加油！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4aa.png" alt="💪" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)

except ValueError as e:
  print(&quot;請輸入數字！&quot;)
  print(e)
except Exception as e:
  print(&quot;發生未知錯誤&quot;)</code></pre>				</div>
				</div>
				<div class="elementor-element elementor-element-5e18fe0 elementor-widget elementor-widget-text-editor" data-id="5e18fe0" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>最後一部分加入了 elif 條件。如果第一個條件沒有達成，有第二、第三、第四個條件可以試。在 Python 裡面加 elif 指令，可以讓 if 條件句多加判斷不同條件。但要注意的是，如果前面的條件達成了，它就會直接執行那個條件並跳出，不再執行後面的條件子句。</p><p>以這邊的範例來講，如果 score 大於等於90 分，就顯示成績是 A；如果大於等於80 分，就顯示成績是 B；如果都不符合，就顯示不及格。</p>								</div>
				</div>
				<div class="elementor-element elementor-element-59aca42 elementor-widget elementor-widget-code-block-for-elementor" data-id="59aca42" data-element_type="widget" data-e-type="widget" data-widget_type="code-block-for-elementor.default">
				<div class="elementor-widget-container">
					<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-python'>score = int(input(&quot;分數？&quot;))

# 先看bool result結果
# score &gt;= 60 scroe有沒有大於等於60?


# 再轉成人類可讀
if score &gt;= 90: #如果score有沒有大於等於60: 做以下的事情
  print(&quot;成績是A！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f389.png" alt="🎉" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)
elif score &gt;= 80: #else if: 否則如果(第一個條件沒達成時，判斷這個條件)
  print(&quot;成績是B！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f389.png" alt="🎉" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)
else: #否則: 做以下的事情
  print(&quot;不及格，要加油！<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4aa.png" alt="💪" class="wp-smiley" style="height: 1em; max-height: 1em;" />&quot;)</code></pre>				</div>
				</div>
				<div class="elementor-element elementor-element-659f753 elementor-widget elementor-widget-text-editor" data-id="659f753" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p style="font-size: 14px; text-align: start; font-family: Roboto, sans-serif; font-weight: 400; color: #000000;">記錄一下自己的心情，就像備課的碎碎念吧。其實這次上課的程式主要是用 ChatGPT 生成。因為我自己撰寫程式的深度和強度比現在入門教學高很多，所以不像大學時期教課時對 Python 理解還沒那麼多。現在講 Python 時，我會把入門、中階、進階混為一談，但實際上在程式領域中學習等級差很多。</p>
<p style="font-size: 14px; text-align: start; font-family: Roboto, sans-serif; font-weight: 400; color: #000000;">為避免自己發生這種狀況，我和 ChatGPT 對話時請它給我合適的 code 範例，不是教我怎麼寫程式或教別人，而是給我合適範例。我拿著範例來解釋和教學，避免拉太多對入門的人來講難度過多的知識點。</p>
<p style="font-size: 14px; text-align: start; font-family: Roboto, sans-serif; font-weight: 400; color: #000000;">線上直播加入多少知識點也是一個思考點。純線上直播不像實體課能知道學生反應和互動節奏，上課節奏慢很多。但線上上課好處是大家輕鬆，不像實體上課有壓力，即使沒有要考試也有實體課程的節奏壓力。而線上直播，我定調成啟發性教學，不一定要讓你成為專業工程師，而是開啟一道大門讓你覺得Python很有趣。</p>
<p style="font-size: 14px; text-align: start; font-family: Roboto, sans-serif; font-weight: 400; color: #000000;">希望來上課或看直播的人都能收穫他們想要的東西，不管是 Python 還是 ChatGPT 或只是聽我講話都可以。如果覺得文章有幫助，可以分享給需要的人，也歡迎留言讓我知道你的感想，你們的留言是我寫文章最大的動力。希望我們都能帶給彼此更好的收穫，一起共好！</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="penci-section penci-disSticky penci-structure-10 elementor-section elementor-top-section elementor-element elementor-element-2b3c8b1 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="2b3c8b1" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="penci-ercol-100 penci-ercol-order-1 penci-sticky-ct    elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d3e4143" data-id="d3e4143" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-28812dd elementor-widget elementor-widget-text-editor" data-id="28812dd" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>教學錄影的影片在這：</p>								</div>
				</div>
				<div class="elementor-element elementor-element-c994ac6 elementor-widget elementor-widget-video" data-id="c994ac6" data-element_type="widget" data-e-type="widget" data-settings="{&quot;youtube_url&quot;:&quot;https:\/\/www.youtube.com\/watch?v=_BVd8LpmKjo&amp;t=2s&quot;,&quot;lazy_load&quot;:&quot;yes&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}" data-widget_type="video.default">
				<div class="elementor-widget-container">
							<div class="elementor-wrapper elementor-open-inline">
			<div class="elementor-video"></div>		</div>
						</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				</div>
		]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
