Chapter at a glance
Comprehensive solutions and study guide for Class 9 Computer Science Chapter 7 Programming Concept (Python) covering programming language hierarchy, Python features, tokens, operators, data types, input/output functions, conditional statements (if-else), loops (for, while), and practical programming examples.
- Introduction to Python & Features
- Tokens: Keywords, Identifiers & Literals
- Python Operators & Expressions
- Input/Output & Type Casting
- Conditional Branching (if, elif, else)
- Looping Constructs (for, while, range)
- Practical Python Programs
Exam focus: Core exam topics include naming rules for identifiers, differences between shell mode vs script mode, while vs for loop syntax, operator precedence, and writing Python programs for basic mathematical and logical problems.
Key formulas and definitions
- Simple Interest: SI = (P * T * R) / 100
- Arithmetic Operators: +, -, *, /, // (floor), % (modulo), ** (power)
- range(start, stop, step) generates integers from start to stop-1
On this page (20 sections)
- The lesson in short
- TheoryCore Concepts & Definitions
- Section B: Python Tokens, Data Types & Operators
- SyntaxTokens in Python
- RulesRules for Naming Python Identifiers
- Data TypesStandard Data Types in Python
- OperatorsPython Operators Overview
- Section C: Input, Output and Type Conversion
- I/OThe input() and print() Functions
- Section D: Control Flow Statements (Conditional & Looping)
- DecisionConditional Branching: if, if-else, if-elif-else
- LoopsIterative Statements: for and while Loops
- Section E: Practical Python Programs with Code and Output
- Lab 1Program 1: Check Odd or Even Number
- Lab 2Program 2: Find the Largest Among Three Numbers
- Lab 3Program 3: Simple Interest Calculator
- Lab 4Program 4: Print Multiplication Table of a Given Number
- Lab 5Program 5: Sum of First N Natural Numbers
- Section F: Textbook Review Questions and Board Preparation
- Exam FocusShort Answer Questions
Solutions and answers
The lesson in short
Python is a modern, high-level, interpreted, interactive, and object-oriented programming language designed by Guido van Rossum in 1991. It emphasizes code readability with clean syntax and minimal boilerplate, making it one of the most popular programming languages globally for beginners, web development, data science, and artificial intelligence.
This chapter introduces core programming logic, Python tokens (keywords, identifiers, literals, operators), data types, input/output operations, and control structures (conditional branching and iterative loops) aligned with the Nepal CDC Class 9 Computer Science curriculum.
TheoryCore Concepts & Definitions
What is a computer program and programming language?
A computer program is a sequence of precise instructions written in a programming language that guides a computer to perform a specific task or solve a computational problem. A programming language is a formal system of notation and syntax used by programmers to communicate instructions to a computer.
What are the main categories of programming languages?
Programming languages are broadly classified into three categories: 1. Low-Level Languages (Machine Language consisting of binary 0s and 1s, and Assembly Language using mnemonic operation codes). 2. High-Level Languages (problem-oriented languages using English-like syntax such as Python, C, C++, and Java). 3. Fourth-Generation Languages (4GLs like SQL for database querying).
Who developed Python and when was it released?
Python was conceived in the late 1980s by Dutch programmer Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands and was officially released in February 1991.
Mention five key features that make Python popular for beginners.
1. Simple and Easy to Learn: Python uses clear, English-like syntax that resembles pseudocode. 2. Interpreted Language: Code is executed line by line, making debugging immediate and straightforward. 3. Cross-Platform / Portable: Python runs seamlessly across Windows, macOS, Linux, and Unix without modification. 4. Free and Open Source: Python is free to download, use, distribute, and modify. 5. Rich Standard Library: Python provides built-in modules for mathematics, string handling, file I/O, networking, and graphics.
Differentiate between Interactive Shell Mode and Script File Mode in Python.
In Interactive Shell Mode (REPL), Python commands are typed directly after the primary prompt (>>>) in the Python Shell/IDLE and executed immediately line by line, ideal for quick testing. In Script File Mode, Python instructions are written into a text file saved with a .py extension and executed all at once, which is necessary for multi-line programs and reusable applications.
Section B: Python Tokens, Data Types & Operators
SyntaxTokens in Python
A token is the smallest individual unit in a Python program. Python recognises five types of tokens: Keywords, Identifiers, Literals, Operators, and Punctuators.
| Token Type | Description | Examples |
|---|---|---|
| Keywords | Reserved words with special predefined meaning that cannot be used as variable names | if, else, elif, while, for, in, def, return, True, False, None, and, or, not |
| Identifiers | User-defined names for variables, functions, and classes following naming rules | student_name, total_marks, radius, calculate_area |
| Literals | Fixed constant data values stored in variables | Integers (25), Floats (3.14), Strings ("Nepal"), Booleans (True, False) |
| Operators | Symbols that trigger mathematical or logical computations | +, -, *, /, //, %, **, ==, !=, >, <, and, or, not |
| Punctuators | Symbols used to organize sentence structure and expressions | colons, parentheses, brackets, commas, periods |
RulesRules for Naming Python Identifiers
- An identifier can contain letters (A-Z, a-z), digits (0-9), and the underscore character (_).
- An identifier MUST begin with a letter or an underscore; it CANNOT begin with a digit (e.g., _total is valid, but 1total is invalid).
- Python is case-sensitive: Total, total, and TOTAL are three distinct identifiers.
- Python keywords cannot be used as identifier names (e.g., class, for, while are forbidden as variable names).
- Special symbols and whitespace characters like @, #, $, %, space, or hyphen are strictly prohibited in identifiers.
Data TypesStandard Data Types in Python
| Data Type | Description | Example Expression |
|---|---|---|
| int | Whole numbers without decimal points (positive, negative, or zero) | age = 15, count = -4 |
| float | Real numbers with fractional / decimal points | gpa = 3.85, pi = 3.14159 |
| str | Sequence of Unicode characters enclosed in quotes | country = "Nepal", greeting = "Namaste" |
| bool | Truth values representing logical states | is_passed = True, has_error = False |
| list | Ordered, mutable sequence of elements enclosed in square brackets | marks = [85, 92, 78, 90] |
OperatorsPython Operators Overview
| Operator Category | Operators | Sample Expression & Output |
|---|---|---|
| Arithmetic Operators | +, -, *, /, // (floor div), % (modulus), ** (exponent) | 17 // 4 gives 4; 17 % 4 gives 1; 2 ** 3 gives 8 |
| Relational / Comparison | ==, !=, >, <, >=, <= | 10 > 5 gives True; 10 == 20 gives False |
| Logical Operators | and, or, not | (5 > 2) and (3 < 1) gives False; not(5 == 5) gives False |
| Assignment Operators | =, +=, -=, *=, /=, //= | x = 10; x += 5 makes x equal to 15 |
Section C: Input, Output and Type Conversion
I/OThe input() and print() Functions
How does the input() function work in Python?
The input() function pauses program execution, displays an optional prompt message, and waits for the user to type input from the keyboard. Crucially, input() ALWAYS returns the entered data as a string (str), regardless of whether the user typed letters or numbers.
What is type casting and why is it necessary with input()?
Type casting is the explicit conversion of a value from one data type to another. Because input() returns string values, mathematical operations cannot be directly performed on numeric user inputs without converting them using int() or float(). For example: age = int(input("Enter your age: ")).
Explain the sep and end parameters in print().
The print() function by default separates multiple items with a single space and terminates output with a newline character. These can be customized, for instance: print("Kathmandu", "Nepal", sep=" - ") prints "Kathmandu - Nepal".
Section D: Control Flow Statements (Conditional & Looping)
DecisionConditional Branching: if, if-else, if-elif-else
Decision-making statements allow a program to test conditions and execute specific blocks of code based on whether the condition evaluates to True or False.
| Structure | General Syntax Description | Typical Use Case |
|---|---|---|
| Simple if | if condition: followed by indented block | Execute an action only when a condition holds True. |
| if-else | if condition: block 1 else: block 2 | Choose between two mutually exclusive alternatives (e.g., Odd or Even). |
| if-elif-else ladder | if cond 1: block 1 elif cond 2: block 2 else: default | Test multiple successive conditions (e.g., Grading system, Menu choices). |
LoopsIterative Statements: for and while Loops
What is the difference between a for loop and a while loop?
A for loop is a count-controlled loop used when the number of iterations is known beforehand, typically iterating over a sequence generated by range(). A while loop is a condition-controlled loop that repeats as long as a boolean test condition remains True, making it suitable when the number of iterations depends on runtime events.
Explain the range() function in Python with examples.
The range() function produces an arithmetic progression of integers. It accepts three parameters: range(start, stop, step). 1. range(5) generates 0, 1, 2, 3, 4 (starts at 0, stops before 5). 2. range(1, 10, 2) generates 1, 3, 5, 7, 9 (starts at 1, increments by 2, stops before 10). 3. range(10, 0, -1) counts down from 10 to 1.
What do the break and continue statements do?
The break statement immediately terminates the innermost enclosing loop and transfers program control to the statement following the loop. The continue statement skips the remainder of the current loop iteration and jumps immediately to the next iteration of the loop.
Section E: Practical Python Programs with Code and Output
Lab 1Program 1: Check Odd or Even Number
Write a Python program to check whether an integer entered by the user is even or odd.
Source Code:
num = int(input("Enter an integer: "))
if num % 2 == 0:
print(f"{num} is an Even number.")
else:
print(f"{num} is an Odd number.")
Sample Run 1: Enter an integer: 14 -> Output: 14 is an Even number.
Sample Run 2: Enter an integer: 27 -> Output: 27 is an Odd number.
Lab 2Program 2: Find the Largest Among Three Numbers
Write a Python program to accept three numbers and determine the largest one.
Source Code:
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
if a >= b and a >= c:
largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c
print(f"The largest number among {a}, {b}, and {c} is {largest}.")
Lab 3Program 3: Simple Interest Calculator
Write a program to calculate Simple Interest and Total Amount given Principal, Time, and Rate.
Source Code:
principal = float(input("Enter principal amount in NPR: "))
time = float(input("Enter time period in years: "))
rate = float(input("Enter annual interest rate in percent: "))
si = (principal * time * rate) / 100
amount = principal + si
print(f"Simple Interest = NPR {si:.2f}")
print(f"Total Amount = NPR {amount:.2f}")
Lab 4Program 4: Print Multiplication Table of a Given Number
Write a program using a for loop to display the multiplication table of any number up to 10.
Source Code:
n = int(input("Enter number for multiplication table: "))
print(f"--- Multiplication Table for {n} ---")
for i in range(1, 11):
print(f"{n} x {i} = {n * i}")
Lab 5Program 5: Sum of First N Natural Numbers
Write a program using a while loop to find the sum of natural numbers from 1 to N.
Source Code:
n = int(input("Enter value of N: "))
total = 0
i = 1
while i <= n:
total += i
i += 1
print(f"The sum of first {n} natural numbers is {total}.")
Section F: Textbook Review Questions and Board Preparation
Exam FocusShort Answer Questions
1. Why is indentation critical in Python?
Unlike languages like C or Java that use curly brackets to delimit blocks of code, Python uses whitespace indentation (typically 4 spaces). All statements within the same block must have the identical level of indentation; inconsistent indentation raises an IndentationError.
2. What is the difference between = and == in Python?
The single equals sign (=) is the Assignment Operator used to assign a value on the right-hand side to a variable on the left-hand side (e.g., x = 10). The double equals sign (==) is the Relational Equality Operator used to compare two values for equality, returning True if they are equal and False otherwise (e.g., x == 10).
3. What is a comment in Python and how is it written?
A comment is non-executable explanatory text written inside source code to enhance readability for human developers. Python ignores comments completely during execution. Single-line comments start with the hash symbol (#), while multi-line comments can be enclosed in triple quotes.
4. What will be the output of print(15 // 2) and print(15 % 2)?
print(15 // 2) performs floor division and outputs 7 (the integer quotient). print(15 % 2) performs modulus division and outputs 1 (the remainder).
5. Explain the purpose of the type() function.
The type() function returns the class type of any Python object or variable passed to it. For example, type(42) returns integer class type, and type("Nepal") returns string class type.
Frequently asked questions
What is Programming Concept ( Python) about?
Comprehensive solutions and study guide for Class 9 Computer Science Chapter 7 Programming Concept (Python) covering programming language hierarchy, Python features, tokens, operators, data types, input/output functions, conditional statements (if-else), loops (for, while), and practical programming examples.
Which topics are covered in Programming Concept ( Python)?
Class 9 Computer Science “Programming Concept ( Python)” covers: Introduction to Python & Features; Tokens: Keywords, Identifiers & Literals; Python Operators & Expressions; Input/Output & Type Casting; Conditional Branching (if, elif, else); Looping Constructs (for, while, range); Practical Python Programs.
What should I focus on in Programming Concept ( Python) for the exam?
Core exam topics include naming rules for identifiers, differences between shell mode vs script mode, while vs for loop syntax, operator precedence, and writing Python programs for basic mathematical and logical problems.
What are the key formulas or definitions in Programming Concept ( Python)?
Simple Interest: SI = (P * T * R) / 100; Arithmetic Operators: +, -, *, /, // (floor), % (modulo), ** (power); range(start, stop, step) generates integers from start to stop-1.
Where can I read the Class 9 Computer Science “Programming Concept ( Python)” solutions?
Right on this page. They are free and you do not need to sign up. For chapter quizzes and the AI tutor, install the Sikshya Plus app.
Study tips
Do not just read it. Practice it.
You have read the solutions for Programming Concept ( Python). Now test yourself, ask the AI tutor and keep your streak going.




- AI quizzes for this chapterTest yourself with instant feedback and explanations after every answer.
- AI tutor, free, 24/7Stuck on a question? Ask in your own words and get a step-by-step explanation.
- 14 AI tools in one appSummarizer, grammar checker, flashcards, essay help, math solver and more.
- Past questions and notesPast papers and your own notes organized chapter by chapter.