我正在尝试将C++代码转换为python但我被卡住了
原始的C++代码
int main(void)
{
int levels = 40;
int xp_for_first_level = 1000;
int xp_for_last_level = 1000000;
double B = log((double)xp_for_last_level / xp_for_first_level) / (levels - 1);
double A = (double)xp_for_first_level / (exp(B) - 1.0);
for (int i = 1; i <= levels; i++)
{
int old_xp = round(A * exp(B * (i - 1)));
int new_xp = round(A * exp(B * i));
std::cout << i << " " << (new_xp - old_xp) << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
python代码
import math
from math import log
from math import exp
levels = 40
xp_for_first_level = 1000
xp_for_last_level = 1000000
B = log(xp_for_last_level / xp_for_first_level) / (levels - 1)
A = xp_for_first_level / (exp(B) - 1.0)
for i in range(1, levels):
old_xp = round(A * exp(B * (i - 1)))
new_xp = round(A * exp(B * i))
print(i + " " + (new_xp - old_xp))
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏我似乎无法完全使用它,当我修复一个错误,我正在创建另一个.
将print行更改为:
print("%i %i" % (i, new_xp - old_xp))
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅此允许的类型转换说明符列表.
或者使用新的格式方法.
| 归档时间: |
|
| 查看次数: |
144 次 |
| 最近记录: |