Variables and Data Types — Intro to Programming Practice Worksheet
A variable stores a value in memory and has a name. Assignment uses = in most languages (x = 5). Variables can be reassigned — the old value is replaced.
Common data types: integers (whole numbers), floats (decimals), strings (text in quotes), booleans (True/False). The type determines what operations are valid — you cannot divide a string by a number.
Declaring variables before use is required in some languages (Java, C++) but not in Python. Choose meaningful names (student_count not x) for readable code.
Skills practiced
- Declaring and assigning variables
- Identifying data types
- Predicting output of simple assignments
- Choosing appropriate types for data
Practice Worksheet: Variables and Data Types
Instructions: Solve each problem carefully. Show all work clearly. Write your final answer in the space provided or on a separate sheet as directed.
-
1.**Multiple Choice:** Which of the following is a valid variable name in Python?
- A. 2ndPlace
- B. my-variable
- C. my_variable
- D. class
-
2.**Short Answer:** What data type would you use to store a person's age? Explain why.
-
3.**Multiple Choice:** Which of the following is an example of a floating-point number?
- A. 42
- B. "3.14"
- C. 3.14
- D. True
-
4.**Free Response:** Write a line of Python code that creates a variable named
scoreand assigns it the integer value 95. -
5.**Short Answer:** What is the difference between the data types
intandfloat? -
6.**Multiple Choice:** Which of the following is NOT a basic data type in most programming languages?
- A. Integer
- B. String
- C. Loop
- D. Boolean
-
7.**Free Response:** Declare a variable called
greetingthat stores the text "Hello, World!". -
8.**Short Answer:** What value does the expression
7 + 3.0produce, and what is its data type? -
9.**Multiple Choice:** Which of these is a Boolean value?
- A. 0
- B. "False"
- C. false
- D. False
-
10.**Free Response:** Explain why the following variable name is invalid in most programming languages:
2fast. Then, suggest a valid alternative.
Answer Key
-
1.
my_variable is valid because it starts with a letter/underscore and contains only letters, digits, and underscores. 2ndPlace starts with a digit, my-variable contains a hyphen, and class is a reserved keyword.Final answer: C
-
2.
Age is typically a whole number (e.g., 15, 21), so an integer data type is appropriate. It does not require decimal precision.Final answer: Integer (int)
-
3.
3.14 is a floating-point number because it has a decimal point. 42 is an integer, "3.14" is a string, and True is a Boolean.Final answer: C
-
4.
Final answer: score = 95
-
5.
Final answer: An int (integer) stores whole numbers without a decimal point (e.g., 5, -3). A float (floating-point) stores numbers with a decimal point (e.g., 5.0, -3.14).
-
6.
Loop is a control structure, not a data type. Integer, string, and Boolean are all basic data types.Final answer: C
-
7.
Final answer: greeting = "Hello, World!"
-
8.
The expression 7 + 3.0 produces 10.0, which is a float because adding an integer and a float results in a float.Final answer: 10.0, float
-
9.
False is a Boolean value in Python (capitalized). false (lowercase) is not recognized as a Boolean in Python.Final answer: D
-
10.
Final answer: The name 2fast is invalid because it starts with a digit. Most languages require variable names to begin with a letter or underscore. A valid alternative could be fast2 or twoFast.
Common mistakes to avoid
- Using = for comparison instead of assignment context
- Confusing string "5" with integer 5
- Forgetting quotes for string literals
- Using reserved words as variable names
Generate your own like this
Want a fresh set of variables and data types problems at your chosen difficulty? Use WorksheetSmith to compile a custom, print-ready PDF in seconds.
Last updated: 2026