1. <legend id='FgsKS'><style id='FgsKS'><dir id='FgsKS'><q id='FgsKS'></q></dir></style></legend>
        <bdo id='FgsKS'></bdo><ul id='FgsKS'></ul>

      <small id='FgsKS'></small><noframes id='FgsKS'>

      <i id='FgsKS'><tr id='FgsKS'><dt id='FgsKS'><q id='FgsKS'><span id='FgsKS'><b id='FgsKS'><form id='FgsKS'><ins id='FgsKS'></ins><ul id='FgsKS'></ul><sub id='FgsKS'></sub></form><legend id='FgsKS'></legend><bdo id='FgsKS'><pre id='FgsKS'><center id='FgsKS'></center></pre></bdo></b><th id='FgsKS'></th></span></q></dt></tr></i><div id='FgsKS'><tfoot id='FgsKS'></tfoot><dl id='FgsKS'><fieldset id='FgsKS'></fieldset></dl></div>

        <tfoot id='FgsKS'></tfoot>

        找到小于 X 数的 2 的最大幂?

        时间:2023-08-30

        <small id='uaOnC'></small><noframes id='uaOnC'>

            <tbody id='uaOnC'></tbody>

            <bdo id='uaOnC'></bdo><ul id='uaOnC'></ul>
            1. <tfoot id='uaOnC'></tfoot>
              <legend id='uaOnC'><style id='uaOnC'><dir id='uaOnC'><q id='uaOnC'></q></dir></style></legend>
              <i id='uaOnC'><tr id='uaOnC'><dt id='uaOnC'><q id='uaOnC'><span id='uaOnC'><b id='uaOnC'><form id='uaOnC'><ins id='uaOnC'></ins><ul id='uaOnC'></ul><sub id='uaOnC'></sub></form><legend id='uaOnC'></legend><bdo id='uaOnC'><pre id='uaOnC'><center id='uaOnC'></center></pre></bdo></b><th id='uaOnC'></th></span></q></dt></tr></i><div id='uaOnC'><tfoot id='uaOnC'></tfoot><dl id='uaOnC'><fieldset id='uaOnC'></fieldset></dl></div>

                  本文介绍了找到小于 X 数的 2 的最大幂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在做这个

                  def power_two(n, base = -1):
                      result = 2 ** base
                      if result < n:
                          base += 1
                          power_two(n, base)
                      else:
                          if result == n:
                              print base
                          else:
                              print base - 1
                  

                  找到小于 X 数的 2 的最大幂的 Python 方法是什么?

                  what is the pythonic way to find largest power of two less than X number?

                  编辑例如:power_two(100) 只返回幂

                  EDIT example: power_two(100) return only the power

                  推荐答案

                  求对数并截断:

                  def power_two(n):
                      return int(math.log(n, 2))
                  

                  这篇关于找到小于 X 数的 2 的最大幂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在python中处理list.index(可能不存在)的最佳方法? 下一篇:如何使用Python在满足两个条件的数组中查找值

                  相关文章

                    • <bdo id='8dJSl'></bdo><ul id='8dJSl'></ul>
                  1. <small id='8dJSl'></small><noframes id='8dJSl'>

                    <legend id='8dJSl'><style id='8dJSl'><dir id='8dJSl'><q id='8dJSl'></q></dir></style></legend>
                    <i id='8dJSl'><tr id='8dJSl'><dt id='8dJSl'><q id='8dJSl'><span id='8dJSl'><b id='8dJSl'><form id='8dJSl'><ins id='8dJSl'></ins><ul id='8dJSl'></ul><sub id='8dJSl'></sub></form><legend id='8dJSl'></legend><bdo id='8dJSl'><pre id='8dJSl'><center id='8dJSl'></center></pre></bdo></b><th id='8dJSl'></th></span></q></dt></tr></i><div id='8dJSl'><tfoot id='8dJSl'></tfoot><dl id='8dJSl'><fieldset id='8dJSl'></fieldset></dl></div>

                      <tfoot id='8dJSl'></tfoot>