from prettytable import PrettyTable
list=[]deffutureInvestmentValue(inAmount,rate,years):for i inrange(1,years +1):
futureInvestment = inAmount +((1+rate)**(12* i))list.append([i,futureInvestment])
table = PrettyTable(['year','Future Value'])for row inlist:
table.add_row(row)print(table)if __name__ =="__main__":
inAmount =int(input("请输入投资额:"))
rate =float(input("请输入百分比格式的年利率:"))/12
futureInvestmentValue(inAmount,rate,years =30)
结果:
请输入投资额:20000
请输入百分比格式的年利率:0.42+------+--------------------+| year | Future Value |+------+--------------------+|1|20001.511068657346||2|20002.283328487214||3|20003.450266111457||4|20005.213588980525||5|20007.87809090076||6|20011.904336239862||7|20017.988269378566||8|20027.181510057857||9|20041.07312790777||10|20062.064316240612||11|20093.78344301082||12|20141.71322131168||13|20214.138407055663||14|20323.57783523589||15|20488.94832503694||16|20738.83448902532||17|21116.429639332677||18|21687.00183612811||19|22549.175599458948||20|23851.979350414535||21|25820.60526515679||22|28795.33418296363||23|33290.353814763395||24|40082.637094532605||25|50346.243470409594||26|65855.25737633757||27|89290.44219593419||28|124702.61545594587||29|178212.8405576684||30|259070.4645564297|+------+--------------------+
defprintChars():for i inrange(73,91):print(chr(i),end=" ")if i%10==0:print("\n")
printChars()
结果:
I J K L M N O P
Q R S T U V W X Y Z
defnumberDayInAYear(year):for i inrange(2010,2021):if i %4==0and i %100!=0or i %400==0:print(i,"年共有366天")else:print(i,"年共有365天")
numberDayInAYear(2010)
结果:
2010 年共有365天
2011 年共有365天
2012 年共有366天
2013 年共有365天
2014 年共有365天
2015 年共有365天
2016 年共有366天
2017 年共有365天
2018 年共有365天
2019 年共有365天
2020 年共有366天
defdistance(x1,x2,y1,y2):
juli =(((x1-x2)**2)+((y1-y2)**2))**0.5print(juli)
distance(2,5,6,8)
结果:3.605551275463989
from prettytable import PrettyTable
defmeisushu(a):
c =[]
b =[]for a inrange(2,23):if a >1:for i inrange(2,a):if a % i ==0:breakelse:
d =2**(a-1)
c.append([a,d])for x in c:if x notin b:
b.append(x)
table = PrettyTable(['a','2**(a-1)'])for row in b:
table.add_row(row)print(table)
meisushu(2)
结果:
+----+----------+| a |2**(a-1)|+----+----------+|3|4||5|16||7|64||9|256||11|1024||13|4096||15|16384||17|65536||19|262144||21|1048576|+----+----------+
import time
localtime = time.asctime(time.localtime(time.time()))print("本地时间为 :", localtime)
结果:本地时间为 : Mon Aug 1922:43:142019