《Python语言程序设计》 第6章编程题答案(6.11~6.19)

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

    [LV.5]常住居民I

    20

    主题

    66

    帖子

    376

    积分

    筑基程序员

    Rank: 3Rank: 3

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

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

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

    x
    6.11
    def computcommission(salesAmount):
       if 0.01 < salesAmount <= 5000:
           commission=salesAmount * 8 / 100
       elif 5000 < salesAmount <= 10000:
           commission=5000*8/100+(salesAmount-5000)*10/100
       else:
           commission=5000*8/100+5000*10/100+(salesAmount-10000)*12/100
       return commission
    def title():
       print('-'*30)
       print('Sales Amount    | Commission')
       print('-'*30)
    def main():
       title()
       for i in range(10000,105000,5000):
           print(' ',format(i,'^6d'),'\t',end='')
           print('|',end='')
           print(' ',format(computcommission(i),'^7.1f'))
    main()
    6.12
    def printChars(ch1,ch2,numberPerLine):
       a=ord(ch1)
       b=ord(ch2)
       count=0
       for i in range(a,b+1):
           print(chr(i),end='')
           count+=1
           if count % numberPerLine ==0:
                print()
    printChars('1','Z',5)
    6.13
    def progression(number):
       sum=0
       for i in range(1,number+1):
           sum+=i/(i+1)
           print(format(i,'6d'),end='|')
           print(format(sum,'^8.4f'))
           print('-'*20)
    number=eval(input('number:'))
    print('-'*20)
    print(format('i','>6s'),end='|')
    print(format('m(i)','^6s'))
    progression(number)
    6.14
    def progression(number):
       sum=0
       for i in range(1,number+1):
           sum+=4 * ( ( (-1) ** (i+1) ) / (2*i-1) )
       print(format(i,'6d'),end='|')
       print(format(sum,'^8.4f'))
       print('-'*20)
    number=eval(input('number:'))
    print('-'*20)
    print(format('i','>6s'),end='|')
    print(format('m(i)','^6s'))
    for i in range(1,number+1,100):
       progression(i)
    6.15
    6.16
    def numberOfDaysInYear(year):
       if (year % 4==0 and year % 100 !=0) or (year % 400 ==0):
           days=366
       else:
           days=365
       return days
    for i in range(2010,2021):
       print(str(i)+'year has '+str(numberOfDaysInYear(i))+'days')
    6.17
    import math
    def isValid(side1,side2,side3):
       if (side1+side2)>=side3 and (side2+side3)>=side1 and (side1+side3)>=side2 :
           return True
       else:
           print('Input is invaild')
    def area(side1,side2,side3):
       if isValid(side1,side2,side3):
           s=(side1+side2+side3)/2
           area=math.sqrt(s*(s-side1)*(s-side2)*(s-side3))
           return area
    side1,side2,side3=eval(input('enter three sides in double:'))
    print('the area of the triangle is '+str(area(side1,side2,side3)))
    6.18
    import random
    def printmatrix(n):
       for i in range(1,n+1):
           print(random.randint(0,1),end='')
           for j in range(1,n):
                print(random.randint(0,1),end='')
           print()
    printmatrix(eval(input('enter n:')))
    6.19
    def leftOfTheLine(x0,y0,x1,y1,x2,y2):
       if (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0)>0:
           print('p2 on the left of line')
    def onTheSameLine(x0,y0,x1,y1,x2,y2):
       if (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0)<0:
           print('p2 on the same line')
    def leftOfTheLine(x0,y0,x1,y1,x2,y2):
       if (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0)==0:
           print('p2 on the right of line')
    x0,y0,x1,y1,x2,y2=eval(input('enter p0,p1,p2:'))
    leftOfTheLine(x0,y0,x1,y1,x2,y2)
    onTheSameLine(x0,y0,x1,y1,x2,y2)
    leftOfTheLine(x0,y0,x1,y1,x2,y2)


    〖下载地址失效反馈〗:

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

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

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

    〖客服24小时咨询〗:

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

    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2019-9-16 10:08
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    0

    主题

    102

    帖子

    334

    积分

    筑基程序员

    Rank: 3Rank: 3

    积分
    334
    发表于 2023-3-24 10:40:21 | 显示全部楼层
    支持楼主,用户楼主,楼主英明呀!!!
    回复

    使用道具 举报

  • TA的每日心情
    郁闷
    2023-11-7 10:15
  • 签到天数: 33 天

    [LV.5]常住居民I

    0

    主题

    122

    帖子

    532

    积分

    终身VIP

    Rank: 12Rank: 12Rank: 12

    积分
    532
    发表于 2023-3-25 04:50:49 | 显示全部楼层
    我擦!我要沙发!
    回复

    使用道具 举报

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

    本版积分规则

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

    QQ群(仅限付费用户)

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