<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 大于等于號 ~~~ 有沒有注意到以上只是些符號,沒有運算操作呢?寫完下面的練習代碼后,再回到上面的列表,寫出每個符號的作用。例如`+`是用來做加法運算的。 ~~~ print "I will now count my chickens:" print "Hens", 25 + 30 / 6 print "Roosters", 100 - 25 * 3 % 4 print "Now I will count the eggs:" print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 print "Is it true that 3 + 2 < 5 - 7?" print 3 + 2 < 5 - 7 print "What is 3 + 2?", 3 + 2 print "What is 5 - 7?", 5 - 7 print "Oh, that's why it's False." print "How about some more." print "Is it greater?", 5 > -2 print "Is it greater or equal?", 5 >= -2 print "Is it less or equal?", 5 <= -2 ~~~ ## 你看到的結果 ~~~ $ 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.使用`#`在代碼每一行的前一行為自己寫一個注釋,說明這一行的作用。2.記得`練習 0`的內容吧?用里邊的方法把`Python`運行起來,然后使用剛才學到的運算符號,把Python當做計算器玩玩。3.自己找個需要計算的東西,寫一個 `.py` 文件把它計算出來。4.有沒有發現有些計算結果是”錯”的呢?計算結果只有整數,沒有小數部分。研究一下這是為什么,搜索一下“浮點數(floating point number)” 是什么東西。5.使用浮點數重寫一遍`ex3.py`,讓它的計算結果更準確(提示: 20.0 是一個浮點數)。 ## 常見問題 ### Q: 為什么`%`表示模除而不是“百分號”? > 這個問題的答案正好就是問什么大部分程序員選擇用這個運算符。平時我們把它看做一個“百分號”。在編程計算中,通常把它和`/`一樣當做除法的運算符。`%`是一個不同的運算,只是用`%`符號來表示。 ### Q: `%`如何運算的? > 另一種說法是, "X除以Y余J." 比如, "100 除以16余數為4." `%` 計算的結果就是這個余數。 ### Q: 運算符的順序是怎樣的? > 在美國我們用一個括弧來指定加減乘除的順序。Python中也同樣遵循這個規律。 ### Q: `/`是如何運算的? > 它只是舍去了小數點后面的部分,比較一下`7.0 / 4.0`和 `7 / 4`,你就會明白其中的不同了。
                  <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>

                              哎呀哎呀视频在线观看