<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 習題 4: 變量(variable)和命名 你已經學會了 print 和算術運算。下一步你要學的是“變量”。在編程中,變量只不過是用來指代某個東西的名字。程序員通過使用變量名可以讓他們的程序讀起來更像英語。而且因為程序員的記性都不怎么地,變量名可以讓他們更容易記住程序的內容。如果他們沒有在寫程序時使用好的變量名,在下一次讀到原來寫的代碼時他們會大為頭疼的。 如果你被這章習題難住了的話,記得我們之前教過的:找到不同點、注意細節。 1. 在每一行的上面寫一行注解,給自己解釋一下這一行的作用。 1. 倒著讀你的 .py 文件。 1. 朗讀你的 .py 文件,將每個字符也朗讀出來。 <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</pre> </div> </td> <td class="code"> <div class="highlight"> <pre>cars = 100&#13; space_in_a_car = 4.0&#13; drivers = 30&#13; passengers = 90&#13; cars_not_driven = cars - drivers&#13; cars_driven = drivers&#13; carpool_capacity = cars_driven * space_in_a_car&#13; average_passengers_per_car = passengers / cars_driven&#13; &#13; &#13; print "There are", cars, "cars available."&#13; print "There are only", drivers, "drivers available."&#13; print "There will be", cars_not_driven, "empty cars today."&#13; print "We can transport", carpool_capacity, "people today."&#13; print "We have", passengers, "to carpool today."&#13; print "We need to put about", average_passengers_per_car, "in each car."&#13; </pre> </div> </td> </tr></tbody></table> Note space_in_a_car 中的 _ 是 下劃線(underscore) 字符。你要自己學會怎樣打出這個字符來。這個符號在變量里通常被用作假想的空格,用來隔開單詞。 ### 你應該看到的結果 ~~~ $ python ex4.py There are 100 cars available. There are only 30 drivers available. There will be 70 empty cars today. We can transport 120.0 people today. We have 90 to carpool today. We need to put about 3 in each car. $ ~~~ ### 加分習題 當我剛開始寫這個程序時我犯了個錯誤,python 告訴我這樣的錯誤信息: ~~~ Traceback (most recent call last): File "ex4.py", line 8, in <module> average_passengers_per_car = car_pool_capacity / passenger NameError: name 'car_pool_capacity' is not defined ~~~ 用你自己的話解釋一下這個錯誤信息,解釋時記得使用行號,而且要說明原因。 更多的加分習題: 1. 我在程序里用了 4.0 作為 space_in_a_car 的值,這樣做有必要嗎?如果只用 4 會有什么問題? 1. 記住 4.0 是一個“浮點數”,自己研究一下這是什么意思。 1. 在每一個變量賦值的上一行加上一行注解。 1. 記住 = 的名字是等于(equal),它的作用是為東西取名。 1. 記住 _ 是下劃線字符(underscore)。 1. 將 python 作為計算器運行起來,就跟以前一樣,不過這一次在計算過程中使用變量名來做計算,常見的變量名有 i, x, j 等等。
                  <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>

                              哎呀哎呀视频在线观看