<pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
    <pre id="vvttv"></pre>

      <p id="vvttv"></p>

          <p id="vvttv"></p>

                <p id="vvttv"></p>

                <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                  <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                    <p id="vvttv"></p>

                    習題 3: 數字和數學計算?

                    每一種編程語言都包含處理數字和進行數學計算的方法。不必擔心,程序員經常撒謊說他們是多么牛的數學天才,其實他們根本不是。如果他們真是數學天才,他們早就去從事數學相關的行業了,而不是寫寫廣告程序和社交網絡游戲,從人們身上偷賺點小錢而已。

                    這章練習里有很多的數學運算符號。我們來看一遍它們都叫什么名字。你要一邊寫一邊念出它們的名字來,直到你念煩了為止。名字如下:

                    • + plus 加號
                    • - minus 減號
                    • / slash 斜杠
                    • * asterisk 星號
                    • % percent 百分號
                    • < less-than 小于號
                    • > greater-than 大于號
                    • <= less-than-equal 小于等于號
                    • >= greater-than-equal 大于等于號

                    有沒有注意到以上只是些符號,沒有運算操作呢?寫完下面的練習代碼后,再回到上面的列表,寫出每個符號的作用。例如 + 是用來做加法運算的。

                     1
                     2
                     3
                     4
                     5
                     6
                     7
                     8
                     9
                    10
                    11
                    12
                    13
                    14
                    15
                    16
                    17
                    18
                    19
                    20
                    21
                    22
                    23
                    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 是一個浮點數)。

                    Project Versions

                    Table Of Contents

                    Previous topic

                    習題 2: 注釋和井號

                    Next topic

                    習題 4: 變量(variable)和命名

                    This Page

                      <pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
                      <pre id="vvttv"></pre>

                        <p id="vvttv"></p>

                            <p id="vvttv"></p>

                                  <p id="vvttv"></p>

                                  <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                                    <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                                      <p id="vvttv"></p>

                                      这里只有精品视频