gpt4 book ai didi

python - 如何在 Python 中找到已知值所需的 2 次幂

转载 作者:行者123 更新时间:2023-12-04 00:13:48 26 4
gpt4 key购买 nike

谁能告诉我一种方法来找到获得已知值所需的 2 的幂。例如,假设我需要找到 32 的 2 的幂。换句话说,如果我知道某个值,如何找到给出该值的 2 的幂。

if the given value is 64 how to get the power of two as 8

我之前搜索过 stackoverflow 中是否有人问过类似的问题,但遗憾的是我找不到任何问题。目前我手头上没有任何东西作为尝试,对此感到抱歉。任何帮助都非常感谢提前。

最佳答案

import math

print (math.log(64, 2))
print (2**math.log(64, 2))

输出:

6
64

关于python - 如何在 Python 中找到已知值所需的 2 次幂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65695040/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com