登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
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)
|