import math from turtle import * import matplotlib.pyplot as plt while True: try: r=int(input("円の半径 r= ")) n=int(input("正多角形の角の個数 n= ")) if n < 3: print("n の値は3以上の整数です。") continue if r > 300: print("r は 300 未満の数です。") continue break except ValueError: pass break reset() shape('turtle') color("black","red") screensize(200,200) title1="円に内接する正 {} 角形" title(title1.format(n)) speed(2) penup() setpos(0,-1*r) pendown() circle(r) begin_fill() circle(r,None,n) end_fill() plt.show() a=2*math.pi/n s=n*0.5*r*r*math.sin(a) title2="半径{}の円に内接する正{}角形の面積は約{}です。" title3="円の面積との差は約{}です。" print(title2.format(r,n,round(s,1))) print(title3.format(round(r*r*math.pi-s,1))) input('type to exit')