我正在尝试将 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;
}
}
蟒蛇代码
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))
感谢任何帮助我似乎无法完全让它工作,当我修复一个错误时,我正在创建另一个错误。