Back to Student Worksheet
CS Grade 6-8 Answer Key

CS: Introduction to Variables and Data Types

Storing information with names and choosing the right data type

Answer Key
Name:
Date:
Score: / 12

CS: Introduction to Variables and Data Types

Storing information with names and choosing the right data type

CS - Grade 6-8

Instructions: Read each problem carefully. Show your work in the space provided.
  1. 1

    In your own words, explain what a variable is in computer programming.

    Think of a variable like a labeled box that holds information.

    A variable is a named place to store a value in a program. The value can be used later and may change while the program runs.
  2. 2

    A program has the statement score = 25. What is the variable name, and what value is stored in it?

    The variable name is score, and the value stored in it is 25.
  3. 3

    Choose the best data type for this value: 42. Explain your choice.

    Integers are used for whole numbers.

    The best data type is an integer because 42 is a whole number with no decimal part.
  4. 4

    Choose the best data type for this value: 3.75. Explain your choice.

    The best data type is a float because 3.75 is a number with a decimal part.
  5. 5

    Choose the best data type for this value: "basketball". Explain your choice.

    Strings are usually written inside quotation marks.

    The best data type is a string because "basketball" is text made of letters.
  6. 6

    Choose the best data type for this value: true. Explain your choice.

    The best data type is a Boolean because true is one of two possible logical values, true or false.
  7. 7

    A student writes age = "12". Is age stored as a number or as text? Explain how you know.

    Look for quotation marks around the value.

    The value is stored as text because 12 is inside quotation marks. Values in quotation marks are strings.
  8. 8

    A program has these statements: points = 10 and points = points + 5. What value does points store after both statements run?

    After both statements run, points stores 15 because the program starts with 10 and then adds 5.
  9. 9

    Write a variable assignment for a player's name, using the variable name playerName and the value Maya.

    Names are strings, so use quotation marks around the value.

    A correct assignment is playerName = "Maya" because the player's name is text and should be stored as a string.
  10. 10

    Write a variable assignment for the number of lives in a game, using the variable name lives and the value 3.

    A correct assignment is lives = 3 because the number of lives is a whole number.
  11. 11

    The variable temperatures stores [68, 70, 72, 69]. What data type is this most likely, and why?

    A list can store several related values together.

    The variable temperatures most likely stores a list because it holds multiple values in one variable.
  12. 12

    A program needs to store whether a user is logged in or not. Choose a good variable name and data type, then explain your answer.

    A good choice is isLoggedIn as a Boolean because the value can be true if the user is logged in or false if the user is not logged in.
LivePhysics™.com CS - Grade 6-8 - Answer Key