首页 > 编程语言 > 详细

python小练习,打出1-100之间的所有偶数,设计一个函数,在桌面上创建10个文件,并以数字命名,复利计算函数

时间:2016-10-31 16:27:11      阅读:2988      评论:0      收藏:0      [点我收藏+]
  练习一:打出1-100之间的所有偶数
def even_print():
    for i in range(1,101):
        if i % 2 == 0:
            print (i)
even_print()

 练习二:设计一个函数,在桌面上创建10个文件,并以数字命名

def text_creation():
    path = ‘C:/Users/Administrator/Desktop‘
    for name in range (1,11):
        with open(path + str(name) + ‘.txt‘,‘w‘) as text:
            text.write(str(name))
            text.close()
            print (‘done‘)
text_creation()

 练习三:复利计算函数

def invest(amount,rate,time):
    print(‘principal amount:{}‘.format(amount))
    for t in range(1,time + 1):
        amount = amount * (1 + rate)
        print (‘year {}: ${}‘.format(t,amount))
invest(100,.05,8)
invest(2000,.025,5)

  

python小练习,打出1-100之间的所有偶数,设计一个函数,在桌面上创建10个文件,并以数字命名,复利计算函数

原文:http://www.cnblogs.com/pythonal/p/6016186.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!