Chapter at a glance
Comprehensive solutions and programming exercises for Class 10 Computer Science Unit 4 Programming in Python, covering data types, arithmetic and logical operators, control flow (if-elif-else, loops), and complete solved Python scripts.
- Python Syntax, Indentation, and Data Types
- Operators: Arithmetic, Relational, Logical
- Conditional Selection: if, elif, and else
- Iteration with for loops and while loops
- Standard Algorithms: Factorial, Prime Check, Fibonacci
Exam focus: Understanding Python indentation rules, tracing output of loops and conditions, and writing correct Python code for prime numbers, factorials, and series generation.
Key formulas and definitions
- Modulo operator: n % 2 == 0 for even check
- Square root optimization: int(n ** 0.5) + 1 for prime testing
On this page (12 sections)
- The lesson in short
- Section A: Python Fundamentals, Data Types, and Operators
- Data TypesCore Data Types in Python
- OperatorsStandard Operators in Python
- Section B: Control Flow: Decision Making and Loops
- ConditionalsConditional Branching: if, elif, and else
- LoopsIterative Loops: for and while
- Section C: Solved Python Textbook Programs
- Code 1Program 1: Check whether a Number is Odd or Even
- Code 2Program 2: Calculate the Factorial of a Positive Integer
- Code 3Program 3: Check Prime Number
- Code 4Program 4: Generate the Fibonacci Series up to N Terms
Solutions and answers
The lesson in short
Python is a high-level, interpreted, dynamically-typed programming language renowned for its elegant, readable syntax, vast standard library, and multi-paradigm flexibility.
Widely deployed in web development, scientific computing, Artificial Intelligence, automation scripting, and educational instruction, Python emphasizes programmer productivity and code clarity.
This comprehensive chapter covers Python syntax rules, basic data types (int, float, str, bool, list), operators, conditional selection statements (if-elif-else), iterative loops (for, while), user-defined functions, and complete solved CDC programming exercises.
Section A: Python Fundamentals, Data Types, and Operators
Data TypesCore Data Types in Python
| Data Type | Keyword | Description | Example Literals |
|---|---|---|---|
| Integer | int | Whole numbers without decimal fractions | x = 42, count = -15 |
| Floating Point | float | Real numbers containing decimal points | pi = 3.14159, g = 9.8 |
| String | str | Ordered sequence of Unicode characters enclosed in quotes | name = "Kathmandu", msg = 'Nepal' |
| Boolean | bool | Logical values representing truth state | flag = True, is_prime = False |
| List | list | Ordered, mutable collection of heterogeneous items | nums = [10, 20, 30], mixed = [1, "apple", True] |
OperatorsStandard Operators in Python
| Operator Category | Symbols | Operation Description | Example Code & Result |
|---|---|---|---|
| Arithmetic | +, -, *, /, //, %, ** | Basic math operations; // is integer floor division, ** is exponentiation | 17 // 3 -> 5; 2 ** 4 -> 16 |
| Relational / Comparison | ==, !=, <, >, <=, >= | Compares two operands; evaluates to True or False | 10 >= 5 -> True; 7 == 9 -> False |
| Logical | and, or, not | Combines boolean expressions based on truth logic | True and False -> False; not False -> True |
| Assignment | =, +=, -=, *=, /= | Assigns and modifies variable values in place | x += 5 is equivalent to x = x + 5 |
Section B: Control Flow: Decision Making and Loops
ConditionalsConditional Branching: if, elif, and else
Python uses indentation (four spaces) rather than curly braces to define code blocks. Example of multi-way conditional structure:
| Structure | Syntax Form | Operational Explanation |
|---|---|---|
| if Statement | if condition: # code | Executes body only if test expression is True |
| if-else | if condition: # A else: # B | Executes block A if True, block B if False |
| if-elif-else | if cond1: # 1 elif cond2: # 2 else: # 3 | Tests cascading conditions sequentially until one evaluates True |
LoopsIterative Loops: for and while
The for loop: Iterates through items in any iterable sequence (such as a list or a range): `for i in range(1, 6): print(i)` outputs numbers 1 through 5.
The while loop: Repeatedly executes statements as long as a test condition remains True: `while n > 0: n -= 1`.
Section C: Solved Python Textbook Programs
Code 1Program 1: Check whether a Number is Odd or Even
Write a Python program to input an integer and determine if it is odd or even.
# Program to check Odd or Even
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.")
Code 2Program 2: Calculate the Factorial of a Positive Integer
Write a Python program to calculate the factorial of a user-supplied integer.
# Program to find Factorial
n = int(input("Enter a positive integer: "))
fact = 1
if n < 0:
print("Factorial does not exist for negative numbers.")
else:
for i in range(1, n + 1):
fact *= i
print(f"The factorial of {n} is {fact}.")
Code 3Program 3: Check Prime Number
Write a Python program to verify whether a given number is Prime or Composite.
# Program to verify Prime Number
n = int(input("Enter a number: "))
if n <= 1:
print(f"{n} is neither prime nor composite.")
else:
is_prime = True
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
is_prime = False
break
if is_prime:
print(f"{n} is a Prime number.")
else:
print(f"{n} is a Composite number.")
Code 4Program 4: Generate the Fibonacci Series up to N Terms
Write a Python program to print the first N terms of the Fibonacci sequence.
# Fibonacci Series generator
n = int(input("How many terms? "))
a, b = 0, 1
print("Fibonacci Series:")
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
print() # newline
Frequently asked questions
What is Programming in Python about?
Comprehensive solutions and programming exercises for Class 10 Computer Science Unit 4 Programming in Python, covering data types, arithmetic and logical operators, control flow (if-elif-else, loops), and complete solved Python scripts.
Which topics are covered in Programming in Python?
Class 10 Computer Science “Programming in Python” covers: Python Syntax, Indentation, and Data Types; Operators: Arithmetic, Relational, Logical; Conditional Selection: if, elif, and else; Iteration with for loops and while loops; Standard Algorithms: Factorial, Prime Check, Fibonacci.
What should I focus on in Programming in Python for the exam?
Understanding Python indentation rules, tracing output of loops and conditions, and writing correct Python code for prime numbers, factorials, and series generation.
What are the key formulas or definitions in Programming in Python?
Modulo operator: n % 2 == 0 for even check; Square root optimization: int(n ** 0.5) + 1 for prime testing.
Where can I read the Class 10 Computer Science “Programming in 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 in 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.