Skip to content

Course home

Sign up

Computational thinking

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
Question 76

An algorithm is designed to calculate the total path length for an autonomous drone using waypoint coordinates.

1      # ----- Global variables -----
2      waypointCoordinates = [(0, 0), (12, 5), (24, -3), (30, 10)]

3
4      # ----- Subprograms -----
5      def computeTotalDistance(coordinates):
6          total_dist = 0.0
7          for i in range(len(coordinates) - 1):
8              x1, y1 = coordinates[i]
9              x2, y2 = coordinates[i+1]
10             total_dist += ((x2 - x1)**2 + (y2 - y1)**2)**0.5
11         return total_dist
12
13     # ----- Main Program -----
14     calculateChoice = input("Compute autonomous trajectory distance? (Y/N) ")
15     if calculateChoice.strip().upper() == "Y":
16         distance = computeTotalDistance(waypointCoordinates)
17         print("Total path length:", distance, "meters")
18     else:
19         print("Navigation standby")

Identify the computational thinking technique demonstrated by encapsulating the mathematical details of the multi-coordinate Euclidean distance formula inside the subprogram computeTotalDistance(), allowing the main program to obtain the total path length without interacting directly with the coordinate structures and loop index arithmetic.

[1]
Markscheme

Computational thinking Questions

  1. GCSE
  2. /Computer Science
  3. /Computational thinking

Question bank