<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 習題 3: 數字和數學計算 每一種編程語言都包含處理數字和進行數學計算的方法。不必擔心,程序員經常撒謊說他們是多么牛的數學天才,其實他們根本不是。如果他們真是數學天才,他們早就去從事數學相關的行業了,而不是寫寫廣告程序和社交網絡游戲,從人們身上偷賺點小錢而已。 這章練習里有很多的數學運算符號。我們來看一遍它們都叫什么名字。你要一邊寫一邊念出它們的名字來,直到你念煩了為止。名字如下: - + plus 加號 - - minus 減號 - / slash 斜杠 - * asterisk 星號 - % percent 百分號 - < less-than 小于號 - > greater-than 大于號 - <= less-than-equal 小于等于號 - >= greater-than-equal 大于等于號 有沒有注意到以上只是些符號,沒有運算操作呢?寫完下面的練習代碼后,再回到上面的列表,寫出每個符號的作用。例如 + 是用來做加法運算的。 <table class="highlighttable"><tbody><tr><td class="linenos"> <div class="linenodiv"> <pre> 1&#13; 2&#13; 3&#13; 4&#13; 5&#13; 6&#13; 7&#13; 8&#13; 9&#13; 10&#13; 11&#13; 12&#13; 13&#13; 14&#13; 15&#13; 16&#13; 17&#13; 18&#13; 19&#13; 20&#13; 21&#13; 22&#13; 23</pre> </div> </td> <td class="code"> <div class="highlight"> <pre>print "I will now count my chickens:"&#13; &#13; print "Hens", 25 + 30 / 6&#13; print "Roosters", 100 - 25 * 3 % 4&#13; &#13; print "Now I will count the eggs:"&#13; &#13; print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6&#13; &#13; print "Is it true that 3 + 2 &lt; 5 - 7?"&#13; &#13; print 3 + 2 &lt; 5 - 7&#13; &#13; print "What is 3 + 2?", 3 + 2&#13; print "What is 5 - 7?", 5 - 7&#13; &#13; print "Oh, that's why it's False."&#13; &#13; print "How about some more."&#13; &#13; print "Is it greater?", 5 &gt; -2&#13; print "Is it greater or equal?", 5 &gt;= -2&#13; print "Is it less or equal?", 5 &lt;= -2&#13; </pre> </div> </td> </tr></tbody></table> ### 你應該看到的結果 ~~~ $ python ex3.py I will now count my chickens: Hens 30 Roosters 97 Now I will count the eggs: 7 Is it true that 3 + 2 < 5 - 7? False What is 3 + 2? 5 What is 5 - 7? -2 Oh, that's why it's False. How about some more. Is it greater? True Is it greater or equal? True Is it less or equal? False $ ~~~ ### 加分習題 1. 使用 # 在代碼每一行的前一行為自己寫一個注解,說明一下這一行的作用。 1. 記得開始時的 <練習 0> 吧?用里邊的方法把 Python 運行起來,然后使用剛才學到的運算符號,把Python當做計算器玩玩。 1. 自己找個想要計算的東西,寫一個 .py 文件把它計算出來。 1. 有沒有發現計算結果是”錯”的呢?計算結果只有整數,沒有小數部分。研究一下這是為什么,搜索一下“浮點數(floating point number)”是什么東西。 1. 使用浮點數重寫一遍 ex3.py,讓它的計算結果更準確(提示: 20.0 是一個浮點數)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看