《python语言程序设计课后题》第5章编程题答案(5.31~5.40)

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

    [LV.5]常住居民I

    20

    主题

    66

    帖子

    376

    积分

    筑基程序员

    Rank: 3Rank: 3

    积分
    376
    发表于 2019-12-7 17:00:13 | 显示全部楼层 |阅读模式

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

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

    x
    5.31:
    year=eval(input('enter the year of you want :'))
    what_day=eval(input('enter the first day of one year: '))
    def calender(month,year,what_day,days):
       print(format(str(month)+str(year),'^50s'))
       print('-'*50)
       print('Sun\tMon\tTue\tWed\tThu\tFri\tSat\t')
       print('  \t'*what_day,end='')
       count=0
       for i in range(1,days+1):
           print(format(i,'^3d'),end=''+'\t')
           count+=1
           if (what_day+count) % 7==0:
                print()
       print()
    calender('January',year,what_day,31)
    FebFirstDay=(what_day+31 % 7) % 7
    if year % 400 ==0 or (year % 4 == 0 and year % 100 != 0):
       days=29
    else:
       days=28
    calender('February',year,FebFirstDay,days)
    if year % 400 ==0 or (year % 4 == 0 and year % 100 != 0):
       MarFirstDay=(FebFirstDay+29 % 7) % 7
    else:
       MarFirstDay=(FebFirstDay+28 % 7) % 7
    calender('March',year,MarFirstDay,31)
    AprFirstDay=(MarFirstDay+31 % 7) % 7
    calender('April',year,AprFirstDay,30)
    MayFirstDay=(AprFirstDay+30 % 7) % 7
    calender('May',year,MayFirstDay,31)
    JunFirstDay=(MayFirstDay+31 % 7) % 7
    calender('June',year,JunFirstDay,30)
    JulFirstDay=(JunFirstDay+30 % 7) % 7
    calender('July',year,JulFirstDay,31)
    AugFirstDay=(JulFirstDay+31 % 7) % 7
    calender('August',year,AugFirstDay,31)
    SepFirstDay=(AugFirstDay+31 % 7) % 7
    calender('September',year,SepFirstDay,30)
    OctFirstDay=(SepFirstDay+30 % 7) % 7
    calender('October',year,OctFirstDay,31)
    NovFirstDay=(OctFirstDay+31 % 7) % 7
    calender('November',year,NovFirstDay,30)
    DecFirstDay=(NovFirstDay+30 % 7) % 7
    calender('December',year,DecFirstDay,31)
    5.32:
    amount=eval(input('enter an amount:'))
    year_rate=eval(input('enter the year_rate:'))
    month=eval(input('enter the month:'))
    total=0
    for i in range(1,month+1):
       total=(100+total)*(1+year_rate/1200)
    print(format(total,'.3f'))
    5.33:
    amount=eval(input('enter an amount:'))
    year_rate=eval(input('enter the year_rate:'))
    month=eval(input('enter the month:'))
    total=amount*(1+year_rate/1200)
    print('Month\tCD Value')
    print(format('1','5s')+'\t'+format(total,'.2f'))
    for i in range(2,month+1):
       total=total*(1+year_rate/1200)
       print(format(i,'<5d')+'\t'+format(total,'.2f'))
    5.34:
    import random
    a=random.randint(0,9)
    b=random.randint(0,9)
    while a==b:
       b=random.randint(0,9)
    else:
       if a == 0:
           print(str(a)+str(b))
       else:
           number=a*10+b
           print(number)
    5.35:
    number=10000
    for j in range(2,number+1):
       sum=0
       for i in range(1,j):
           if j % i == 0:
                sum+=i
       if sum == j:
           print(j)
    5.36:
    import random
    count1=0
    count2=0
    while count1 < 2 and count2 < 2:
       guess=eval(input('enter scissor(0),rock(1),paper(2):'))
       computer=random.randint(0,2)
       if guess == computer:
           print('computer is'+str(computer)+',it is draw!')
       elif (guess==0 and computer==1) or (guess==1 and computer==2) or (guess==2 and computer==0):
           print('computer is'+str(computer)+',computer win!')
           count1+=1
       elif (guess==0 and computer==2) or (guess==1 and computer==0) or (guess==2 and computer==1):
           print('computer is'+str(computer)+',you win!')
           count2+=1
    print('computer win '+str(count1)+' times,you win '+str(count2)+' times,game over!')
    5.37:
    import math
    sum=0
    for i in range(1,625):
       sum=sum+1/(math.sqrt(i)+math.sqrt(i+1))
    print(sum)
    5.38:
    import time
    number=eval(input('enter the number of seconds:'))
    while number > 0:
       print(str(number)+'seconds remaining')
       time.sleep(1)
       number-=1
    print('stopped')
    5.39:
    salary=5000
    fees=0
    number=0.01
    while (salary+fees)<30000:
       if 0.01 <= number <= 5000:
           fees=number * 8 /100
       elif 5000 < number <= 10000:
           fees=5000*8/100+(number-5000)*10/100
       elif 10000 < number :
           fees=5000*8/100+5000*10/100+(number-10000)*12/100
       number+=0.01
    print(number,salary+fees)
    5.40:
    import random
    count1=0
    count2=0
    for i in range(1000000):
       number=random.randint(0,1)
       if number==0:
           count1+=1
       else:
           count2+=1
    print('正面出现了'+str(count1)+'次,反面出现了'+str(count2)+'次')

    〖下载地址失效反馈〗:

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

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

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

    〖客服24小时咨询〗:

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

    回复

    使用道具 举报

  • TA的每日心情

    2019-11-6 17:11
  • 签到天数: 2 天

    [LV.1]初来乍到

    0

    主题

    91

    帖子

    294

    积分

    终身VIP

    Rank: 12Rank: 12Rank: 12

    积分
    294
    发表于 2023-3-24 16:30:39 | 显示全部楼层
    佩服佩服!
    回复

    使用道具 举报

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

    [LV.4]偶尔看看III

    0

    主题

    135

    帖子

    485

    积分

    筑基程序员

    Rank: 3Rank: 3

    积分
    485
    发表于 2023-3-27 18:36:06 | 显示全部楼层
    为保住菊花,这个一定得回复!
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2021-9-21 08:31
  • 签到天数: 18 天

    [LV.4]偶尔看看III

    0

    主题

    125

    帖子

    469

    积分

    终身VIP

    Rank: 12Rank: 12Rank: 12

    积分
    469
    发表于 2023-3-27 22:37:00 | 显示全部楼层
    为保住菊花,这个一定得回复!
    回复

    使用道具 举报

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

    本版积分规则

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

    QQ群(仅限付费用户)

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