Python Variables Quiz for 8th Grade
1. What is a variable in Python?
a. A container for storing data values
b. A type of loop
c. A mathematical operation
d. A built-in function
2. Which of the following is a valid variable name in Python?
a. 2myVariable
b. my-variable
c. my_variable
d. my variable
3. What symbol is used to assign a value to a variable in Python?
a. ==
b. :=
c. ->
d. =
4. Which of these is NOT a valid way to declare a variable in Python?
a. x = 5
b. y = "Hello"
c. z := 3.14
d. var int a = 10
5. What will be the output of the following code: x = 5; x = x + 1; print(x)
a. 5
b. 6
c. 1
d. Error
6. Which data type is used for whole numbers in Python?
a. float
b. int
c. str
d. bool
7. What is the correct way to create a variable named 'age' with a value of 13?
a. 13 = age
b. age == 13
c. variable age = 13
d. age = 13
8. In Python, which statement is true about variable names?
a. They can start with a number
b. They are case-sensitive
c. They can contain spaces
d. They must be in all caps
9. What will be the value of 'y' after this code: x = 10; y = x
a. x
b. 10
c. 0
d. None
10. Which of the following is an example of a floating-point variable?
a. age = 13
b. name = "Alice"
c. is_student = True
d. height = 5.2
11. What happens if you try to use a variable before assigning a value to it?
a. It automatically gets assigned a value of 0
b. Python assigns it a random value
c. You get a NameError
d. The program crashes
12. How can you check the data type of a variable in Python?
a. checktype(variable)
b. variable.type()
c. type(variable)
d. datatype(variable)
13. What will be the output of: x = 5; x += 3; print(x)
a. 5
b. 3
c. 8
d. 15
14. Which of these is a valid way to create multiple variables with the same value?
a. x, y, z == 1, 1, 1
b. x = y = z = 1
c. x = 1 & y = 1 & z = 1
d. (x, y, z) <- (1, 1, 1)
15. What is the purpose of using variables in programming?
a. To make the code longer
b. To store and manipulate data
c. To create loops
d. To define functions
16. In Python, which of these is NOT a valid variable name?
a. _myvar
b. myVar
c. MYVAR
d. class
17. What will be the value of 'z' after this code: x = 5; y = 2; z = x * y
a. 7
b. 52
c. 10
d. 25
18. Which statement about Python variables is false?
a. Variables can change type during program execution
b. Variables must be declared with a specific type
c. Variables can be reassigned new values
d. Variables can hold different types of data
19. What does the following code do? x, y = 10, 20
a. Creates a list with values 10 and 20
b. Assigns 10 to x and 20 to y
c. Causes an error
d. Creates a tuple with values 10 and 20
20. Which of the following is an example of a string variable?
a. grade = 7
b. pi = 3.14
c. message = "Hello, World!"
d. is_python = True