Data Types CS Thinking Example 3

Follow the full solution, then compare it with the other examples linked below.

Example 3

medium
For each scenario, choose the most appropriate data type: (a) a student's name, (b) number of students in a class, (c) whether a student passed, (d) a student's average grade (e.g., 87.5).

Solution

  1. 1
    Step 1: (a) Name is text โ†’ string. (b) Count of students is a whole number โ†’ integer.
  2. 2
    Step 2: (c) Passed or not is yes/no โ†’ boolean. (d) Average can have decimals โ†’ float/real.

Answer

(a) String, (b) Integer, (c) Boolean, (d) Float/Real.
Choosing the correct data type ensures data is stored efficiently and operations behave as expected. Using an integer for a count prevents nonsensical fractional students.

About Data Types

Categories that classify data values and determine which operations can validly be performed on them. Common data types include integers, floating-point numbers, strings, booleans, and arrays, each with its own set of permitted operations.

Learn more about Data Types โ†’

More Data Types Examples