-3
x年後の母集団を計算するプログラムを作成したいと考えています。モジュラー式を使用する方法/大きなintergerで作業する方法
2002年のポップは62億人で、毎年1.3%増加します。私が使用する
式は、私が一緒に動作するように6.2-2を容易にするにはどうすればよい
population = ((1.013)**x) * 6.2B
のですか?
x年後の母集団を計算するプログラムを作成したいと考えています。モジュラー式を使用する方法/大きなintergerで作業する方法
2002年のポップは62億人で、毎年1.3%増加します。私が使用する
式は、私が一緒に動作するように6.2-2を容易にするにはどうすればよい
population = ((1.013)**x) * 6.2B
のですか?
ここにあなたのコードがあります。よく読んで学びなさい。これは恐らくあなたがGoogleで解決できた問題です。
import math
def calculate_population(years_since_2002): #the original calculation
population_2002 = 6.2*10**9
final_population = int(((1.013)**years_since_2002)*population_2002)
return final_population
def pretty_print(num,trunc=0):
multiplier = int(math.log10(num)) #finds the power of 10
remainder = float(num)/(10**multiplier) #finds the float after
str_remainder = str(remainder)
if trunc != 0:
str_remainder = remainder[:trunc+1] #truncates to trunc digits total
return str_remainder+'e'+str(multiplier) #can also be print
なぜ6200000000は効かないのですか?または6.2E9? –
@Mario - おそらく浮動小数点演算の考え方を理解していないと思います。 –
6.2e9はいいですが、私は6200000000が好きではありません。 – DSM