The math library contains mathematical formulas. We can use the math library to find the value of an expression.
First import the math library (two methods):
import math
from math import x #x表示math库中方法
Example:
import math def main(): money_everyweek = 10 # 每周存入的金额 i = 1 # 第几周 increasing_money = 10 # 每周递增的金额 end_week = 52 # 总共存52周 saving_money = 0 # 目前账户有多少金额 money_list = [] while i <= end_week : saving_money = math.fsum(money_list) #现在账户有多少元 money_list.append(money_everyweek) print('第{}周,存入{}元,目前账户有{}元'.format(i, money_everyweek, saving_money)) money_everyweek += increasing_money #每周存入的金额数为上一周的加上递增金额 i += 1 # 递增的周数 if __name__ =='__main__': main()
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to import math library in python. For more information, please follow other related articles on the PHP Chinese website!