《Python语言程序设计》 第5章编程题答案(5.23-5.30)

5
回复
955
查看
[复制链接]
  • TA的每日心情
    开心
    2020-1-15 12:08
  • 签到天数: 43 天

    [LV.5]常住居民I

    20

    主题

    66

    帖子

    376

    积分

    筑基程序员

    Rank: 3Rank: 3

    积分
    376
    发表于 2019-12-5 22:33:36 | 显示全部楼层 |阅读模式

    登录后查看本帖详细内容!

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    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)

    〖下载地址失效反馈〗:

    下载地址如果失效,请反馈。反馈地址: https://www.fstcode.com/thread-5527-1-1.html

    〖赞助VIP免灵石下载全站资源〗:

    全站资源高清无密,每天更新,VIP特权: https://www.fstcode.com/plugin.php?id=threed_vip

    〖客服24小时咨询〗:

    有任何问题,请点击右侧客服QQ咨询。

    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2022-3-25 23:33
  • 签到天数: 16 天

    [LV.4]偶尔看看III

    0

    主题

    135

    帖子

    485

    积分

    筑基程序员

    Rank: 3Rank: 3

    积分
    485
    发表于 2023-3-24 16:28:54 | 显示全部楼层
    LZ帖子给力,给回复下吧
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2022-1-21 08:55
  • 签到天数: 21 天

    [LV.4]偶尔看看III

    0

    主题

    109

    帖子

    430

    积分

    终身VIP

    Rank: 12Rank: 12Rank: 12

    积分
    430
    发表于 2023-3-25 21:22:42 | 显示全部楼层
    打酱油的人拉,回复下赚取积分
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2019-10-18 11:11
  • 签到天数: 1 天

    [LV.1]初来乍到

    0

    主题

    89

    帖子

    274

    积分

    终身VIP

    Rank: 12Rank: 12Rank: 12

    积分
    274
    发表于 2023-3-26 04:30:27 | 显示全部楼层
    好,很好,非常好!
    回复

    使用道具 举报

  • TA的每日心情

    2019-11-23 20:56
  • 签到天数: 8 天

    [LV.3]偶尔看看II

    0

    主题

    103

    帖子

    347

    积分

    终身VIP

    Rank: 12Rank: 12Rank: 12

    积分
    347
    发表于 2023-3-26 14:49:54 | 显示全部楼层
    楼猪V5啊
    回复

    使用道具 举报

  • TA的每日心情

    2024-4-2 16:21
  • 签到天数: 37 天

    [LV.5]常住居民I

    0

    主题

    155

    帖子

    642

    积分

    终身VIP

    Rank: 12Rank: 12Rank: 12

    积分
    642
    发表于 2023-3-27 20:24:16 | 显示全部楼层
    LZ敢整点更有创意的不?兄弟们等着围观捏~
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

     
    在线客服
    点击这里给我发消息 点击这里给我发消息
    用心服务所有程序员,做最好的编程视频网站
    QQ:354410543
    周一至周日 00:00-24:00
    联系站长:admin@fstcode.com

    QQ群(仅限付费用户)

    Powered by "真全栈程序员" © 2010-2023 "真全栈程序员" 本站资源全部来自互联网及网友分享-如有侵权请发邮件到站长邮箱联系删除!