Variables and Data Types — Intro to Programming Übungsblatt
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.
Geübte Fähigkeiten
- Declaring and assigning variables
- Identifying data types
- Predicting output of simple assignments
- Choosing appropriate types for data
Übungsblatt: Variables and Data Types
Anleitung: Löse jede Aufgabe sorgfältig. Zeige deine Arbeit klar. Schreibe deine endgültige Antwort in das vorgesehene Feld oder wie angewiesen auf ein separates Blatt.
-
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 — Übungsblatt (Fortsetzung)
-
2.**Short Answer:** What data type would you use to store a person's age? Explain why.
Variables and Data Types — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
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 — Übungsblatt (Fortsetzung)
-
9.**Multiple Choice:** Which of these is a Boolean value?
- A. 0
- B. "False"
- C. false
- D. False
Variables and Data Types — Übungsblatt (Fortsetzung)
-
10.**Free Response:** Explain why the following variable name is invalid in most programming languages:
2fast. Then, suggest a valid alternative.
Lösungsschlüssel
-
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.Endgültige Antwort: 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.Endgültige Antwort: 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.Endgültige Antwort: C
-
4.
Endgültige Antwort: score = 95
-
5.
Endgültige Antwort: 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).
Lösungsschlüssel (Fortsetzung)
-
6.
Loop is a control structure, not a data type. Integer, string, and Boolean are all basic data types.Endgültige Antwort: C
-
7.
Endgültige Antwort: 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.Endgültige Antwort: 10.0, float
-
9.
False is a Boolean value in Python (capitalized). false (lowercase) is not recognized as a Boolean in Python.Endgültige Antwort: D
-
10.
Endgültige Antwort: 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.
Häufige Fehler, die es zu vermeiden gilt
- Using = for comparison instead of assignment context
- Confusing string "5" with integer 5
- Forgetting quotes for string literals
- Using reserved words as variable names
Erstelle dein eigenes Arbeitsblatt
Möchtest du neue variables and data types-Aufgaben in deiner gewünschten Schwierigkeit? Nutze WorksheetSmith, um in Sekunden ein individuelles, druckfertiges PDF zu erstellen.
Individuelles Variables and Data Types-Arbeitsblatt erstellen
Zuletzt aktualisiert: 2026