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

                    習題 12: 提示別人?

                    當你鍵入 raw_input() 的時候,你需要鍵入 () 也就是“括號(parenthesis)”。這和你格式化輸出兩個以上變量時的情況有點類似,比如說 "%s %s" % (x, y) 里邊就有括號。對于 raw_input 而言,你還可以讓它顯示出一個提示,從而告訴別人應該輸入什么東西。你可以在 () 之間放入一個你想要作為提示的字符串,如下所示:

                    y = raw_input("Name? ")
                    

                    這句話會用 “Name?” 提示用戶,然后將用戶輸入的結果賦值給變量 y。這就是我們提問用戶并且得到答案的方式。

                    也就是說,我們的上一個練習可以使用 raw_input 重寫一次。所有的提示都可以通過
                    raw_input 實現。
                    1
                    2
                    3
                    4
                    5
                    6
                    age = raw_input("How old are you? ")
                    height = raw_input("How tall are you? ")
                    weight = raw_input("How much do you weigh? ")
                    
                    print "So, you're %r old, %r tall and %r heavy." % (
                        age, height, weight)
                    

                    你應該看到的結果?

                    $ python ex12.py
                    How old are you? 35
                    How tall are you? 6'2"
                    How much do you weight? 180lbs
                    So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
                    $
                    

                    加分習題?

                    1. 在命令行界面下運行你的程序,然后在命令行輸入 pydoc raw_input 看它說了些什么。如果你用的是 Window,那就試一下 python -m pydoc raw_input
                    2. 輸入 q 退出 pydoc。
                    3. 上網找一下 pydoc 命令是用來做什么的。
                    4. 使用 pydoc 再看一下 open, file, os, 和 sys 的含義。看不懂沒關系,只要通讀一下,記下你覺得有意思的點就行了。

                    Project Versions

                    Table Of Contents

                    Previous topic

                    習題 11: 提問

                    Next topic

                    習題 13: 參數、解包、變量

                    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>

                                      这里只有精品视频