<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 程序:相加兩個數字 > 原文: [https://www.programiz.com/python-programming/examples/add-number](https://www.programiz.com/python-programming/examples/add-number) #### 在該程序中,您將學習加兩個數字并使用`print()`函數顯示它。 要理解此示例,您應該了解以下 [Python 編程](/python-programming "Python tutorial")主題: * [Python 輸入,輸出和導入](/python-programming/input-output-import) * [Python 數據類型](/python-programming/variables-datatypes) * [Python 運算符](/python-programming/operators) * * * 在下面的程序中,我們使用`+`運算符將兩個數字相加。 ## 示例 1:加兩個數字 ```py # This program adds two numbers num1 = 1.5 num2 = 6.3 # Add two numbers sum = num1 + num2 # Display the sum print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) ``` **輸出** ```py The sum of 1.5 and 6.3 is 7.8 ``` 下面的程序計算用戶輸入的兩個數字的和。 ## 示例 2:用用戶輸入相加兩個數字 ```py # Store input numbers num1 = input('Enter first number: ') num2 = input('Enter second number: ') # Add two numbers sum = float(num1) + float(num2) # Display the sum print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) ``` **輸出**: ```py Enter first number: 1.5 Enter second number: 6.3 The sum of 1.5 and 6.3 is 7.8 ``` 在此程序中,我們要求用戶輸入兩個數字,此程序顯示用戶輸入的兩個數字的總和。 我們使用內置函數`input()`進行輸入。 由于`input()`返回一個字符串,因此我們使用`float()`函數將該字符串轉換為數字。 然后,將數字相加。 作為替代方案,我們可以在單個語句中執行此加法,而無需使用任何變量,如下所示。 ```py print('The sum is %.1f' %(float(input('Enter first number: ')) + float(input('Enter second number: ')))) ``` 盡管此程序不使用任何變量(內存有效),但更難閱讀。
                  <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>

                              哎呀哎呀视频在线观看