CHAPTER 4 – VERY ABLE VARIABLES
MULTIPLE CHOICE QUESTIONS
- What will be the output of the following code?
x = 7
y = 3
x = x + y
y = x - y
x = x - y
print(x, y)
a. 7 3
b. 3 7
c. 10 4
d. Error
- Consider this code:
a = "5"
b = 2
print(a * b)
What will be the output?
a. 7
b. 10
c. 55
d. 55 (string repeated)
- If we run the following code:
p = 10
q = 3
print(p / q, p // q, p % q)
What will be displayed?
a. 3.3, 3, 1
b. 3.33, 3, 1
c. 3.3, 3.0, 1.0
d. Error
- Which of the following variable names is valid in Python?
a. break
b. user@name
c. _totalMarks
d. my name
- What will be the output of this program?
x = 2
y = 5
z = x ** y // y
print(z)
a. 32
b. 6
c. 12
d. 10
FILL IN THE BLANKS
- Variables that are declared inside a function are called __________ variables.
- The
//operator always gives the __________ part of division. - In Python, variable names are __________ sensitive.
- A constant is generally written in __________ letters.
- The
input()function always returns data as __________.
DESCRIPTIVE QUESTIONS
- Write a program that takes three numbers as input and prints the largest number among them.
- Predict the output of the following code:
x = 10
y = x
x = x + 5
print(x, y)
- Explain the difference between mutable and immutable data types in Python with examples.
- Write a program that accepts two numbers and swaps their values without using a third variable.
- Why does the following code throw an error? Rewrite it correctly.
1value = 100
print(1value)
Answer Key
ANSWER KEY
MULTIPLE CHOICE QUESTIONS
- b. 3 7
- Code swaps values of
xandyusing arithmetic.
- d. 55 (string repeated)
"5" * 2→"55"(string repetition, not multiplication).
- b. 3.33, 3, 1
p / q = 10/3 = 3.33,p // q = 3,p % q = 1.
- c. _totalMarks
- Other options invalid (keywords, special characters, spaces).
- b. 6
x ** y = 2 ** 5 = 32,32 // 5 = 6.
FILL IN THE BLANKS
- local
- integer / floor
- case
- capital / uppercase
- string
DESCRIPTIVE QUESTIONS
- Program to find largest among three numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest =", a)
elif b >= a and b >= c:
print("Largest =", b)
else:
print("Largest =", c)
- Output prediction
x = 10
y = x
x = x + 5
print(x, y)
- Output:
15 10 - Because
ystores the old value ofx.
- Mutable vs Immutable
- Mutable: Can be changed after creation (e.g.,
list,dict). Example:
lst = [1,2,3]
lst.append(4) # list changes
- Immutable: Cannot be changed after creation (e.g.,
int,str,tuple). Example:
x = 5
x = x + 1 # creates new object, old one unchanged
- Swapping without third variable
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
a, b = b, a
print("After swapping: a =", a, "b =", b)
- Why error?
- Variable names cannot start with a digit.
- Corrected:
value1 = 100
print(value1)
