登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
4.21 from turtle import* import math x1,y1=eval(input('输入圆心的坐标:')) x2,y2=eval(input('输入一个点的坐标:')) radius=eval(input('输入圆半径:')) penup() goto(x1,y1-radius) pendown() circle(radius) penup() goto(x2,y2) pendown() dot(3,'red') done() distance=math.sqrt((x2-x1)**2+(y2-y1)**2) if distance < radius: print('point('+str(x2)+','+str(y2)+') is in thecircle') else: print('point('+str(x2)+','+str(y2)+') is not in thecircle') 4.22 from turtle import* import math x1,y1=eval(input('请输入圆心:')) x2,y2=eval(input('请输入长和宽:')) x3,y3=eval(input('输入一点的坐标:')) penup() goto(x1+x2/2,y1) pendown() left(90) forward(y2/2) left(90) forward(x2) left(90) forward(y2) left(90) forward(x2) left(90) forward(y2/2) penup() goto(x3,y3) pendown() dot(3,'red') done() if ( abs(x3+x1)-abs(x1) <abs(x2)-abs(x1) ) and ( abs(y3+y1)-abs(y1) <abs(y2)-abs(y1) ): print('point('+str(x3)+','+str(y3)+') is in therectangle ') elif ( abs(x3+x1)-abs(x1) == abs(x2)-abs(x1) ) and ( abs(y3+y1)-abs(y1) <abs(y2)-abs(y1) ): print('point('+str(x3)+','+str(y3)+') is on thewidth side ') elif ( abs(x3+x1)-abs(x1) <abs(x2)-abs(x1) ) and ( abs(y3+y1)-abs(y1) == abs(y2)-abs(y1) ): print('point('+str(x3)+','+str(y3)+') is on the lengthside ') elif ( abs(x3+x1)-abs(x1) >abs(x2)-abs(x1) ) and ( abs(y3+y1)-abs(y1) >abs(y2)-abs(y1) ): print('point('+str(x3)+','+str(y3)+') is out of therectangle ') 4.23: import random number=random.randint(1,13) if number==1: number='A' if number==11: number='J' if number==12: number='Q' if number==13: number='K' color=random.randint(1,4) if color==1: color='梅花' if color==2: color='红桃' if color==3: color='方块' if color==4: color='黑桃' print('the card you picked is '+color+str(number)) 4.25: x1,y1,x2,y2,x3,y3,x4,y4=eval(input('输入两条线段的四个点坐标:')) if (( y1-y2 ) * ( x3-x4 ) - ( x1-x2 ) * ( y3-y4 ) ) != 0: x=( ( ( ( y1-y2 ) * x1 - ( x1-x2 )*y1 ) * ( x2-x4 ) )-( ( ( y3-y4 ) *x3-( x3-x4 ) * y3 ) * ( x1-x2 ) ) )/\ ( ( y1-y2 ) * ( x3-x4 ) - (x1-x2 ) * ( y3-y4 ) ) y=( ( ( ( y3-y4 ) * x3 - ( x3-x4 )*y3 ) * ( y1-y2 ) )-( ( ( y1-y2 ) *x1-( x1-x2 ) * y1 ) * ( y3-y4 ) ) )/\ ( ( y1-y2 ) * ( x3-x4 ) - ( x1-x2 ) * ( y3-y4 ) ) print(x,y) else: print('eorro') 4.26: number=eval(input('输入一个三位整数:')) if99< number <1000 : iftype(number) == type(1): a=number // 100 b=number % 10 if a==b : print(str(number)+'is apalindrome') else: print(str(number)+'is not apalindrome') else: print('number is not int') else: print('input eorro') 4.27: x,y=eval(input('输入一个点的坐标:')) if (0< x <200) and (y < (100-0.5*x)) : print('the point is in the triangle') else: print('the point is not in the triangle') 4.28: x1,y1,w1,h1=eval(input('输入第一个矩形的坐标以及宽和高:')) x2,y2,w2,h2=eval(input('输入第二个矩形的坐标以及宽和高:')) if (x1-(w1-w2)/2)<=x2<=(x1+(w1-w2)/2) and (y1-(h1-h2)/2)<=y2<=(y1+(h1-h2)/2): print('r2 is insider1') elif ((x1-(w1+w2)/2)<=x2<(x1-(w1-w2)/2) or (x1+(w1-w2)/2)<x2<=(x1+(w1+w2)/2)) and \ ((y1-(h1+h2)/2)<=y2<(y1-(h1-h2)/2) or (y1+(h1-h2)/2)<y2<=(y1+(h1+h2)/2)): print('r2 overlapsr1') else: print('r2 does notoverlap r1') 4.29: import math x1,y1,r1=eval(input('输入第一个圆的坐标以及半径:')) x2,y2,r2=eval(input('输入第二个圆的坐标以及半径:')) ifmath.sqrt((x1-x2)**2+(y1-y2)**2) <= abs(r1-r2): print('circle2 isinside circle1') elifabs(r1-r2)<math.sqrt((x1-x2)**2+(y1-y2)**2)<=r1+r2: print('circle2overlaps circle1') else: print('circle2 doesnot overlaps circle1') 4.30: import time zone=eval(input('输入时区:')) seconds=int(time.time()) second=seconds% 60 miniute=seconds// 60 % 60 hour=seconds //3600 % 24 if1<=hour<=12: am_pm='am' hour+=zone print('the currenttime is '+str(hour)+':'+str(miniute)+':'+str(second)+am_pm) else: am_pm='pm' hour=(hour+zone)% 12 print('the currenttime is '+str(hour)+':'+str(miniute)+':'+str(second)+am_pm) 4.31: x0,y0,x1,y1=eval(input('输入起始点p0和终点p1坐标')) x2,y2=eval(input('输入要判断的点p2的坐标')) if (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0)>0: print('p2在线的左边') elif (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0)==0: print('p2在线的右边') else: print('p2在同一条线上') 4.32: x0,y0,x1,y1=eval(input('输入起始点p0和终点p1坐标')) x2,y2=eval(input('输入要判断的点p2的坐标')) if ((x1-x0)*(y2-y0)-(x2-x0)*(y1-y0))<0: print('p2在线上') else: print('p2不在线上') 4.33: number=eval(input('输入一个十进制整数:')) number_ox=number % 16 if number <= 15: if number_ox==10: number_ox='A' elif number_ox==11: number_ox='B' elif number_ox==12: number_ox='C' elif number_ox==13: number_ox='D' elif number_ox==14: number_ox='E' elif number_ox==15: number_ox='F' print(number_ox) else: print('invalid input') 4.34: ox=input('输入一个十六进制字符:') if ox == 'a' or ox=='A': print(10) elif ox== 'b' or ox=='B': print(11) elif ox== 'c' or ox=='C': print(12) elif ox== 'd' or ox=='D': print(13) elif ox== 'e' or ox=='E': print(14) elif ox== 'f' or ox=='F': print(15) elif 0 <= eval(ox) <= 9: print(eval(ox)) else: print('eorro') 4.35-4.39略,与之前题目相似,只是多了绘图过程
|