Variables and Data Types — Fiche d'exercices de Intro to Programming
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.
Compétences travaillées
- Declaring and assigning variables
- Identifying data types
- Predicting output of simple assignments
- Choosing appropriate types for data
Fiche d'exercices : Variables and Data Types
Consignes : Résous chaque problème avec soin. Montre clairement tout ton travail. Écris ta réponse finale dans l'espace prévu ou sur une feuille séparée comme indiqué.
-
1.**Multiple Choice:** Which of the following is a valid variable name in Python?
- A. 2ndPlace
- B. my-variable
- C. my_variable
- D. class
Variables and Data Types — Fiche d'exercices (suite)
-
2.**Short Answer:** What data type would you use to store a person's age? Explain why.
Variables and Data Types — Fiche d'exercices (suite)
-
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
Variables and Data Types — Fiche d'exercices (suite)
-
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?
Variables and Data Types — Fiche d'exercices (suite)
-
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
Variables and Data Types — Fiche d'exercices (suite)
-
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?
Variables and Data Types — Fiche d'exercices (suite)
-
9.**Multiple Choice:** Which of these is a Boolean value?
- A. 0
- B. "False"
- C. false
- D. False
Variables and Data Types — Fiche d'exercices (suite)
-
10.**Free Response:** Explain why the following variable name is invalid in most programming languages:
2fast. Then, suggest a valid alternative.
Corrigé
-
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.Réponse finale : 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.Réponse finale : 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.Réponse finale : C
-
4.
Réponse finale : score = 95
-
5.
Réponse finale : 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).
Corrigé (suite)
-
6.
Loop is a control structure, not a data type. Integer, string, and Boolean are all basic data types.Réponse finale : C
-
7.
Réponse finale : 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.Réponse finale : 10.0, float
-
9.
False is a Boolean value in Python (capitalized). false (lowercase) is not recognized as a Boolean in Python.Réponse finale : D
-
10.
Réponse finale : 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.
Erreurs fréquentes à éviter
- Using = for comparison instead of assignment context
- Confusing string "5" with integer 5
- Forgetting quotes for string literals
- Using reserved words as variable names
Générez la vôtre
Vous voulez un nouvel ensemble de problèmes de variables and data types à la difficulté de votre choix ? Utilisez WorksheetSmith pour compiler un PDF personnalisé prêt à imprimer en quelques secondes.
Générer une fiche personnalisée sur Variables and Data Types
Dernière mise à jour : 2026