Python #1 Fundamentals

CS25C02 Unit 1 | Introduction to Python Study Hub
Unit I · Introduction to Python

Think logically.
Code creatively.

Interactive study material for CS25C02 – Computer Programming: Python. Learn the fundamentals through explanations, worked examples, short activities, and a live Python runner in every topic.

📘 Beginner-friendly notes▶ Run Python in browser🧩 Practice + quiz📱 Mobile-friendly
Study progress
0 of 6 topics completed

Unit I learning path

🧠

1. Problem Solving

Identify inputs, processing steps, and expected outputs.

Study topic →
🗺️

2. Algorithms

Represent solutions with algorithms, flowcharts, and pseudocode.

Study topic →
🐍

3. Python Modes

Understand interactive mode, scripts, comments, indentation, and errors.

Study topic →
📦

4. Variables & Types

Store values and work with Python's basic data types.

Study topic →
➗

5. Operators

Evaluate arithmetic expressions and operator precedence.

Study topic →
🧰

6. Built-ins & Imports

Use built-in functions and import tools from modules.

Study topic →
Before running code: The first run downloads the Pyodide Python runtime from a CDN, so an internet connection is required. After loading, Python code runs in your browser. If the browser blocks external scripts or the Blogger theme removes scripts, test the published page and allow the Pyodide CDN.

1. Problem solving and problem analysis

Problem solving means understanding a task and developing a clear sequence of steps to produce the required result. A problem analysis chart records the inputs, processing, and outputs before coding.

Worked example: Area of a rectangle

InputProcessingOutput
Length and breadthArea = length × breadthArea of rectangle

Method: identify the known values, choose the formula, calculate the result, and display it.

▶ Python Lab 1 · Rectangle areaEdit the code, then run it.
Ready. Click Run Python to execute this code.
Output will appear here.

2. Algorithms, flowcharts, and pseudocode

An algorithm is a finite sequence of unambiguous steps that solves a problem. A flowchart uses symbols and arrows to show the steps visually. Pseudocode describes the logic in plain, structured language without strict programming syntax.

Flowchart symbolPurpose
OvalStart / End
ParallelogramInput / Output
RectangleProcessing / calculation
DiamondDecision, such as Yes / No
ArrowDirection of flow

Pseudocode: larger of two numbers

START
INPUT a, b
IF a > b THEN
    DISPLAY a
ELSE
    DISPLAY b
END IF
STOP
▶ Python Lab 2 · Larger of two numbersTry changing a and b.
Ready. Click Run Python to execute this code.
Output will appear here.

3. Interactive mode, script mode, comments, indentation, and errors

Interactive mode: type an expression at the Python prompt and see the result immediately. Script mode: save statements in a .py file and run the file.

  • Comments: start with #; Python ignores them during execution.
  • Indentation: spaces at the start of a line define a code block. Four spaces are the common convention.
  • Syntax error: code breaks Python's grammar.
  • Runtime error: an error occurs while the program is running.
  • Logic error: the program runs but produces the wrong answer.
▶ Python Lab 3 · Comments and indentationTry changing the score.
Ready. Click Run Python to execute this code.
Output will appear here.

4. Variables, reserved words, and data types

A variable is a name that refers to a value. Python determines a value's type at runtime. Use descriptive names such as student_name and total_marks.

Identifier rules

  • Start with a letter or underscore; do not start with a digit.
  • Use letters, digits, and underscores only.
  • Names are case-sensitive: score and Score differ.
  • Do not use reserved keywords such as if, for, class, or return.
TypeExampleMeaning
intage = 19Integer
floatheight = 1.72Decimal number
strname = "Jamal"Text
boolpassed = TrueTrue or False
NoneTypevalue = NoneNo value assigned
▶ Python Lab 4 · Variables and typesChange values or add another variable.
Ready. Click Run Python to execute this code.
Output will appear here.

5. Arithmetic operators and expressions

OperatorOperationExampleResult
+Addition7 + 29
-Subtraction7 - 25
*Multiplication7 * 214
/True division7 / 23.5
//Floor division7 // 23
%Remainder7 % 21
**Exponentiation7 ** 249

Parentheses can make the intended order clear. In general, exponentiation is evaluated before multiplication and division, which are evaluated before addition and subtraction.

▶ Python Lab 5 · Expressions and precedenceExperiment with the expressions.
Ready. Click Run Python to execute this code.
Output will appear here.

6. Built-in functions and importing from packages

Python provides built-in functions that are ready to use. A module is a file containing Python definitions and statements. Import a module to use additional functionality.

FunctionExamplePurpose
print()print("Hello")Display output
type()type(4.2)Inspect a value's type
len()len("Python")Count items
sum()sum([2, 3, 4])Add values
max() / min()max([2, 9, 4])Find largest / smallest

Example import: import math makes names such as math.sqrt() and math.pi available.

▶ Python Lab 6 · Built-ins and math moduleTry a different radius.
Ready. Click Run Python to execute this code.
Output will appear here.

Practical activities

Complete these exercises by editing the relevant code lab. Check each task after you have run and understood your solution.

🧩 Quick self-check quiz

Choose one answer for each question, then check your score.

1. Which stage calculates the result in an IPO chart?
2. Which flowchart symbol represents a decision?
3. Which character begins a Python comment?
4. What is the type of 3.5?
5. What is 17 % 5?
6. Which statement imports the math module?

Recommended references

🐍 CS25C02 Python Study Hub · Learn, run, test, debug, and create.

Comments

Popular posts from this blog

index.html

#Python YT Videos for Jamal Engineering Students