python
主页 > 脚本 > python >

python中如何导入math库方法

2019-07-03 | 秩名 | 点击:
本篇文章介绍python中如何导入math库方法

math库中包含了数学公式,我们可以通过用math库求表达式的值

首先导入math库(两种方法):


import math

from math import x #x表示math库中方法

例:

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()

 
 
原文链接:http://www.php.cn/python-tutorials-424824.html
相关文章
最新更新