-3

x年後の人口を計算するプログラムを作りたいです。

2002年の人口は62億人で、毎年1.3%増加しています。

私が使用する式は

population = ((1.013)**x) * 6.2B

6.2Bを使いやすくするにはどうすればよいですか?

4

1 に答える 1

1

これがあなたのコードです。よく読んで学びましょう。これはおそらく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
于 2012-03-03T02:26:36.380 に答える