Chapter 4 – Very Able Variables | Python Class 7 MCQs, Exercises & Programs – Set 3

CHAPTER 4 – VERY ABLE VARIABLES

MULTIPLE CHOICE QUESTIONS

  1. 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


  1. 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)


  1. 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


  1. Which of the following variable names is valid in Python?
    a. break
    b. user@name
    c. _totalMarks
    d. my name

  1. 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

  1. Variables that are declared inside a function are called __________ variables.
  2. The // operator always gives the __________ part of division.
  3. In Python, variable names are __________ sensitive.
  4. A constant is generally written in __________ letters.
  5. The input() function always returns data as __________.


DESCRIPTIVE QUESTIONS

  1. Write a program that takes three numbers as input and prints the largest number among them.

  1. Predict the output of the following code:
x = 10
y = x
x = x + 5
print(x, y)

  1. Explain the difference between mutable and immutable data types in Python with examples.

  1. Write a program that accepts two numbers and swaps their values without using a third variable.

  1. Why does the following code throw an error? Rewrite it correctly.
1value = 100
print(1value)

Answer Key

ANSWER KEY

MULTIPLE CHOICE QUESTIONS

  1. b. 3 7
  • Code swaps values of x and y using arithmetic.
  1. d. 55 (string repeated)
  • "5" * 2"55" (string repetition, not multiplication).
  1. b. 3.33, 3, 1
  • p / q = 10/3 = 3.33, p // q = 3, p % q = 1.
  1. c. _totalMarks
  • Other options invalid (keywords, special characters, spaces).
  1. b. 6
  • x ** y = 2 ** 5 = 32, 32 // 5 = 6.

FILL IN THE BLANKS

  1. local
  2. integer / floor
  3. case
  4. capital / uppercase
  5. string

DESCRIPTIVE QUESTIONS

  1. 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)

  1. Output prediction
x = 10
y = x
x = x + 5
print(x, y)
  • Output: 15 10
  • Because y stores the old value of x.

  1. 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

  1. 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)

  1. Why error?
  • Variable names cannot start with a digit.
  • Corrected:
value1 = 100
print(value1)

Leave a Reply

Discover more from Abhyas

Subscribe now to keep reading and get access to the full archive.

Continue reading