<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之旅 廣告
                # Python 條件控制 ## if 語句 Python中if語句的一般形式如下所示: ``` if condition_1: statement_block_1 elif condition_2: statement_block_2 else: statement_block_3 ``` 如果 "condition_1" 為 True 將執行 "statement_block_1" 塊語句,如果 "condition_1" 為False,將判斷 "condition_2",如果"condition_2" 為 True 將執行 "statement_block_2" 塊語句,如果 "condition_2" 為False,將執行"statement_block_3"塊語句。 Python中用elif代替了else if,所以if語句的關鍵字為:if – elif – else。 **注意:** * 1、每個條件后面要使用冒號(:),表示接下來是滿足條件后要執行的語句塊。 * 2、使用縮進來劃分語句塊,相同縮進數的語句在一起組成一個語句塊。 * 3、在Python中沒有switch – case語句。 ### 實例 以下實例演示了狗的年齡計算判斷: ``` age = int(input("Age of the dog: ")) print() if age < 0: print("This can hardly be true!") elif age == 1: print("about 14 human years") elif age == 2: print("about 22 human years") elif age > 2: human = 22 + (age -2)*5 print("Human years: ", human) ### input('press Return>') ``` 將以上腳本保存在dog.py文件中,并執行該腳本: ``` python dog.py Age of the dog: 1 about 14 human years ``` 以下為if中常用的操作運算符: | 操作符 | 描述 | | --- | --- | | `<` | 小于 | | `<=` | 小于或等于 | | `>` | 大于 | | `>=` | 大于或等于 | | `==` | 等于,比較對象是否相等 | | `!=` | 不等于 | ### 實例 ``` # 程序演示了 == 操作符 # 使用數字 print(5 == 6) # 使用變量 x = 5 y = 8 print(x == y) ``` 以上實例輸出結果: ``` False False ``` high_low.py文件: ``` #!/usr/bin/python3 # 該實例演示了數字猜謎游戲 number = 7 guess = -1 print("Guess the number!") while guess != number: guess = int(input("Is it... ")) if guess == number: print("Hooray! You guessed it right!") elif guess < number: print("It's bigger...") elif guess > number: print("It's not so big.") ```
                  <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>

                              哎呀哎呀视频在线观看