登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
5.23: loanamount=eval(input('enter loanamount:')) loanyears=eval(input('enter number ofyears for loan:')) year_rate=eval(input('enter the rateof year:')) print('Interest Rate Monthly Payment Total Payment') while year_rate <= 8.000: month_rate=year_rate/1200 month_payment=loanamount*month_rate/(1-1/(1+month_rate)**(loanyears*12)) print(format(year_rate,'10.3f')+'%'+format(month_payment,'10.2f')+format(month_payment*12*5,'10.2f')) year_rate+=0.125 5.24: loanamount=eval(input('enter loanamount:')) loanyears=eval(input('enter number ofyears for loan:')) year_rate=eval(input('enter the rateof year:')) month_rate=year_rate/1200 month_payment=loanamount*month_rate/(1-1/(1+month_rate)**(loanyears*12)) total_payment=month_payment*12*loanyears balance=loanamount print(format(month_payment,'.2f')) print(format(total_payment,'.2f')) print('payment#\tInterest\tPrincipal\tBalance') for i inrange(1,loanyears*12+1): interest=month_rate*balance principal=month_payment-interest balance=balance-principal print(i,'\t\t',format(interest,'.2f'),'\t\t',format(principal,'.2f'),'\t',format(balance,'.2f')) 5.25: #左往右: n=50000 sum=0 for i inrange(1,n+1): sum+=1/i print(sum) #结果:11.397003949278504 #右往左 n=50000 sum=0 for i inrange(n,0,-1): sum+=1/i print(sum) #结果:11.397003949278519 5.26: i=99 sum=0 while i >= 3 : sum += (i-2) / i i-=2 print(sum) 5.27: i=1 pi=0 number=10000 for j inrange(10): while i <= number : pi+=4*((-1)**(i+1)/(2*i-1)) i+=1 number+=10000 print(pi) 5.28: for i inrange(1,11,1): item=0 while i >= 1: n=1/i for j inrange(1,i): n=n*(1/(i-j)) item=item+n*i i-=1 print(item) 5.29: count=0 is_leapyear=True for i in range(2001,2101): if i % 400 == 0 or (i % 4 == 0 and i % 100 != 0): is_leapyear=True else: is_leapyear=False if is_leapyear: count+=1 print(i,end=',') if count % 10 ==0: print() 5.30: year=eval(input('enter the year of you want :')) what_day=eval(input('enter the first day of one year: ')) FebFirstDay=(what_day+31 % 7) % 7 if year % 400 ==0 or (year % 4 == 0 and year % 100 != 0): MarFirstDay=(FebFirstDay+29 % 7) % 7 else: MarFirstDay=(FebFirstDay+28 % 7) % 7 AprFirstDay=(MarFirstDay+31 % 7) % 7 MayFirstDay=(AprFirstDay+30 % 7) % 7 JunFirstDay=(MayFirstDay+31 % 7) % 7 JulFirstDay=(JunFirstDay+30 % 7) % 7 AugFirstDay=(JulFirstDay+31 % 7) % 7 SepFirstDay=(AugFirstDay+31 % 7) % 7 OctFirstDay=(SepFirstDay+30 % 7) % 7 NovFirstDay=(OctFirstDay+31 % 7) % 7 DecFirstDay=(NovFirstDay+30 % 7) % 7 print(FebFirstDay,MarFirstDay,AprFirstDay,MayFirstDay,JunFirstDay,JulFirstDay, AugFirstDay,SepFirstDay,OctFirstDay,NovFirstDay,DecFirstDay)
|