<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ***** # 7.1 函數 input()的工作原理 程序等待用戶輸入,并在用戶按回車鍵后繼續運行。輸入存儲在變量message中 ``` message = input("Tell me something, and I will repeat it back to you: ") print(message) ``` 函數input()接受一個參數:即要向用戶顯示的提示或說明,讓用戶知道該如何做 ## 7.1.1 編寫清晰的程序 每當你使用函數input()時,都應指定清晰而易于明白的提示,準確地指出你希望用戶提供 什么樣的信息——指出用戶該輸入任何信息的提示都行,如下所示: ``` name = input("Please enter your name: ") print("Hello, " + name + "!") ``` ## 7.1.2 使用 int()來獲取數值輸入 使用函數input()時, Python將用戶輸入解讀為字符串 例如: 用戶輸入的是數字21,但我們請求Python提供變量age的值時,它返回的是'21'——用戶輸入的數值的字符串表示。 ``` >>> age = input("How old are you? ") How old are you? 21 >>> age '21' ``` 函數int()將數字的字符串表示轉換為數值表示,例如: ``` height = input("How tall are you, in inches? ") height = int(height) if height >= 36: print("\\nYou're tall enough to ride!") ``` ## 7.1.3 求模運算符 ``` >>> 4 % 3 1 ``` # 7.2 while 循環簡介 ## 7.2.1 使用 while 循環 ``` current_number = 1 while current_number <= 5: print(current_number) current_number += 1 ``` ## 7.2.3 使用標志 flag ``` active = True while active: message = input(prompt) if message == 'quit': active = False else: print(message) ``` ## 7.2.4 在循環中使用break ## 7.2.4 在循環中使用continue # 7.3 使用 while 循環來處理列表和字典 **注意** ``` a = {} if a : #字典或列表為空可以當做布爾值的false ```
                  <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>

                              哎呀哎呀视频在线观看