Skip to content

令和8年度 ITパスポート試験 問88

This question's explanation and your answers so far.

問88
頻出度★★☆

プログラミングすることによって,ペンの上げ下げ,直進及び右回りの方向転換が可能なロボットがある。このロボットに1辺が1mの正六角形を描画させるプログラムを作成した。次の正六角形描画プログラムの a,b に入れる字句の適切な組合せはどれか。 〔正六角形描画プログラム〕 (1) ペンを下ろす。 (2) 処理回数のカウンタに| a |を設定する。 (3) 次の処理を順に実行する。  ・1m 直進する。  ・右回りに| b |度方向転換する。  ・処理回数のカウンタに1を加える。 (4) 処理回数のカウンタが6未満の場合は,(3) に戻る。 (5) ペンを上げる。

出典 令和8年度 ITパスポート試験 問88
解説

問 88

  • ア

    正解 The correct answer is ア (a:0, b:60). First consider b. When drawing a regular hexagon in one stroke, the angle by which the direction of travel is turned at each vertex is not the interior angle but the exterior angle, where exterior angle = 360 ÷ number of vertices = 360 ÷ 6 = 60 degrees. So b should be 60. Next consider a. The loop continues under the condition 'if the processing-count counter is less than 6, return to (3)', and exactly 6 sides must be drawn. If a is set to 0, then each time the body of (3) runs (move straight 1 m, turn 60 degrees right, add 1 to the counter), the counter increases as 1, 2, 3, 4, 5, 6, and when it reaches 6 the condition 'less than 6' becomes false for the first time, so the loop exits. That is, the body runs exactly 6 times, 6 sides are drawn, and the regular hexagon is completed. Therefore ア with a:0, b:60 is appropriate.

  • Incorrectイ

    a:0 is correct, but b:120 is wrong. 120 degrees is the interior angle of a regular hexagon, not the angle by which the direction of travel is turned. The angle to turn is the 60-degree exterior angle. Turning 120 degrees each time makes the turn too large to form a hexagon; the figure closes too early (it becomes an equilateral triangle), so it is inappropriate.

  • Incorrectウ

    b:60 is correct, but a:1 is wrong. If the counter starts at 1, then each time the body runs it increases as 2, 3, 4, 5, 6, and after running 5 times the counter becomes 6 and the loop exits. Only 5 sides are drawn, so it does not form a regular hexagon. The initial value must be 0.

  • Incorrectエ

    Both a:1 and b:120 are wrong. With a:1 the loop runs only 5 times, drawing only 5 sides; b:120 is the interior angle, not the angle to turn (the 60-degree exterior angle). Wrong on both counts.

ここがポイント
  • When drawing a regular polygon with a robot (turtle graphics), the angle to turn at each vertex is not the interior angle but the exterior angle, where exterior angle = 360 degrees ÷ number of vertices. For a regular hexagon this is 60 degrees.
  • For counter-controlled iteration, trace the initial value and the continuation condition to confirm the number of executions. With initial value 0 and the continuation condition 'less than 6', the body runs exactly 6 times.
用語

Your answers