1、设计这样-个函数,在桌面的文件夹上创建10个文本,以数字给它们命名。
def creat_file():
for i in range(1,10):
desktop_path= 'C://Users//Tania//Desktop//'
i = str(i)
full_path= desktop_path + i + '.txt'
file = open(full_path,'w')
file.close()
creat_file()
2、复利是一件神奇的事情,正如富兰克林所说:“复利是能够将所有铅块变成金块的
石头”。设计一个复利计算函数invest(), 它包含三个参数: amount (资金),
rate (利率), time (投资时间)。输入每个参数后调用函数,应该返回每一年的资
金总额。它看起来就应该像这样(假设利率为5%) :
def invest(amount,rate,time):
amount=input('请输入本金:')
amount = int(amount)
rate == 0.5
year = input('请输入存款年份:')
year = int (year)
i = 1
while i <= year:
money = amount * pow(1.05,i)
print('year{}:{}'.format(i,money))
i = i + 1
invest(100,0.05,8)
3、打印1~100内的偶数
for i in range(1,101):
while i % 2 == 0:
print(i)
i = i +1