Skip to content
Exercises · Q2

Q.Write the corresponding Python assignment statements:

a) Assign 10 to variable length and 20 to variable breadth.
b) Assign the average of values of variables length and breadth to a variable sum.
c) Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.
d) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.
e) Assign the concatenated value of string variables first, middle and last to variable fullname. Make sure to incorporate blank spaces appropriately between different parts of names.
Yanam BieapTextbookSubjective· 3mImportance★★★★★est
59% · 29/49 Questions
✓ Free question

Five direct assignment statements — including a parallel (tuple) assignment for the three name parts and string concatenation with explicit spaces for the full name.

The idea. Assignment binds a name to a value with =; Python also supports parallel assignment (a, b = 1, 2) and builds strings with the concatenation operator +.

# a) Assign 10 to length and 20 to breadth
length = 10
breadth = 20
# (equivalently: length, breadth = 10, 20)

# b) Average of length and breadth into sum
sum = (length + breadth) / 2       # (10 + 20) / 2 = 15.0

# c) List of strings into stationery
stationery = ['Paper', 'Gel Pen', 'Eraser']

# d) Three strings into first, middle, last (parallel assignment)
first, middle, last = 'Mohandas', 'Karamchand', 'Gandhi'

# e) Concatenated full name with single spaces between the parts
fullname = first + ' ' + middle + ' ' + last

Verification of (e):

>>> fullname
'Mohandas Karamchand Gandhi'

Key points

  • (b) needs parentheses: (length + breadth) / 2. Without them, operator precedence would compute length + (breadth / 2) = 20.0 — the wrong average. Division / always yields a float, so sum is 15.0.
  • (d) parallel assignment unpacks the right-hand tuple left to right — one tidy line instead of three.
  • (e) the ' ' literals supply the blank spaces the question asks for; + on strings concatenates.
Watch out

Naming a variable sum (as the question directs) shadows the built-in function sum() for the rest of the program — fine for this exercise, but avoid it in real code.

✓Final answer

a) length = 10 ; breadth = 20 b) sum = (length + breadth) / 2 c) stationery = ['Paper', 'Gel Pen', 'Eraser'] d) first, middle, last = 'Mohandas', 'Karamchand', 'Gandhi' e) fullname = first + ' ' + middle + ' ' + last → 'Mohandas Karamchand Gandhi'.

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.