Skip to content
Worked Examples · Example 5.1

Q.Example 5.1:
#Variable amount is the total spending on
#grocery
amount = 3400
#totalMarks is sum of marks in all the tests
#of Mathematics
totalMarks = test1 + test2 + finalTest

Yanam CbseNCERTSubjective· 2mImportance★★★★★est
2% · 1/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Example 5.1 is about choosing meaningful variable names (amount, totalMarks) and documenting code with # comments — and it quietly assumes test1, test2 and finalTest already have values.

The concept is a variable naming convention: a variable name should tell the reader what the value means. amount immediately says "a sum of money"; totalMarks says "marks added up". Compare with a = 3400 — legal, but meaningless to a reader. The lines beginning with # are comments: Python ignores everything after # on a line, so they exist purely for the human reader.

#Variable amount is the total spending on
#grocery
amount = 3400
#totalMarks is sum of marks in all the tests
#of Mathematics
totalMarks = test1 + test2 + finalTest

What each statement does:

  • amount = 3400 — creates the variable amount and binds it to the integer object 3400.
  • totalMarks = test1 + test2 + finalTest — evaluates the right-hand side and binds the result to totalMarks. Note the camelCase style (totalMarks) — a common convention for multi-word names; test1/test2/finalTest also show that digits are allowed in names (just not as the first character).

An honest execution note: as printed, this fragment is not runnable on its own — test1, test2 and finalTest are used before being assigned, so Python raises:

NameError: name 'test1' is not defined
``` …

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.