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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Python 程序:查找平方根 > 原文: [https://www.programiz.com/python-programming/examples/square-root](https://www.programiz.com/python-programming/examples/square-root) #### 在該程序中,您將學習使用指數運算符和`math`模塊查找數字的平方根。 要理解此示例,您應該了解以下 [Python 編程](/python-programming "Python tutorial")主題: * [Python 輸入,輸出和導入](/python-programming/input-output-import) * [Python 數據類型](/python-programming/variables-datatypes) * [Python 運算符](/python-programming/operators) * * * ## 示例:對于正數 ```py # Python Program to calculate the square root # Note: change this value for a different result num = 8 # To take the input from the user #num = float(input('Enter a number: ')) num_sqrt = num ** 0.5 print('The square root of %0.3f is %0.3f'%(num ,num_sqrt)) ``` **輸出** ```py The square root of 8.000 is 2.828 ``` 在此程序中,我們將數字存儲在`num`中,并使用`**`指數運算符查找平方根。 該程序適用于所有正實數。 但是對于負數或復數,可以按以下步驟進行。 ## 源代碼:實數或復數 ```py # Find square root of real or complex numbers # Importing the complex math module import cmath num = 1+2j # To take input from the user #num = eval(input('Enter a number: ')) num_sqrt = cmath.sqrt(num) print('The square root of {0} is {1:0.3f}+{2:0.3f}j'.format(num ,num_sqrt.real,num_sqrt.imag)) ``` **輸出**: ```py The square root of (1+2j) is 1.272+0.786j ``` 在此程序中,我們使用`cmath`(復雜數學)模塊中的`sqrt()`函數。 請注意,我們也使用`eval()`函數而不是`float()`來轉換復數。 另外,請注意輸出格式化的方式。 查找有關 Python 中的[字符串格式的更多信息](http://docs.python.org/3/library/string.html#format-string-syntax "String formatting in Python")。
                  <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>

                              哎呀哎呀视频在线观看