CHAPTER 4 – VERY ABLE VARIABLES
MULTIPLE CHOICE QUESTIONS
- Which of the following is a valid variable name in Python?
a. 2value
b. _value2
c. value-2
d. my value
- What will be the output of the following code?
x = 15
y = 4
print(x % y)
a. 3
b. 4
c. 15
d. 11
- If we write the following program:
a = "10"
b = "20"
print(a + b)
What will be the output?
a. 30
b. 1020
c. Error
d. None
- What will the following program display if the input is 7?
num = int(input("Enter a number: "))
print(num * 2)
a. 7
b. 14
c. num*2
d. Error
- Which operator is used for exponentiation in Python?
a. ^
b. **
c. //
d. %
FILL IN THE BLANKS
- A variable in Python is created when we assign a __________ to it.
- The function __________ is used to accept input from the user.
- Integer type variables are declared without any special keyword; for example, x = __________.
- The __________ operator is used for floor division in Python.
- Python keywords like __________ cannot be used as variable names.
DESCRIPTIVE QUESTIONS
- Define a variable. Give two examples of valid and invalid variable names.
- Explain the difference between integer division (//) and normal division (/). Give an example of each.
- Write a Python program that takes two numbers as input and displays their sum, difference, product, and quotient.
- What is type casting? Write a program that takes a string input
"25"and converts it into an integer.
- List any 5 rules for naming variables in Python.
Answer Key
MULTIPLE CHOICE QUESTIONS
- b. _value2
- a. 3
- b. 1020
- b. 14
- b. **
FILL IN THE BLANKS
- value
- input()
- 10 (or any integer value)
- //
- if, while, for (any Python keyword is valid as example)
DESCRIPTIVE QUESTIONS
- Define a variable with examples
- A variable is a named memory location used to store data.
- Valid:
age,_marks - Invalid:
1value,my-name
- Difference between integer division and normal division
/→ Normal division (always returns float), e.g.,7/2 = 3.5//→ Floor division (integer part only), e.g.,7//2 = 3
- Program for sum, difference, product, quotient
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)
print("Difference =", a - b)
print("Product =", a * b)
print("Quotient =", a / b)
- Type casting example
s = "25"
num = int(s)
print(num) # Output: 25 as integer
- Five rules for naming variables
Case-sensitive (Name ≠ name)
Must start with a letter or underscore
Cannot start with a digit
No spaces allowed
Cannot use special characters (like !, @, #, -)
Cannot use Python keywords (like if, for, while)
