Skip to Content

CL-9-Session-1 & 2 Revision of Python.pptx

REVISION OF PYTHON CODING

"Python is a great way to get started in programming because of its simplicity and breadth."

 -- Guido van Rossum
(Father of the Python programming language)


Introduction

A programming language is a formal language that provides instructions for a computer to follow, enabling humans to communicate with and control computers. Python is a versatile and popular programming language, known for its readability and ease of use.

Pre-requisite Knowledge

Learners should
  • Have basic computer literacy.
  • Understand the concept of instructions/commands.
  • Have an interest in problem-solving and logic building.

Learning Objectives

By completing this revision, learners will
  • Understand Python's syntax and basic structure.
  • Use variables and follow naming rules.
  • Work with core data types.

Tools and Materials Required

  • Operating System Windows (7, 8, 10, 11)
  • Python Interpreter
  • Install from https://www.python.org
  • Comes with built-in tools like IDLE (a simple code editor)

Conditional Programming

Conditional programming is also known as conditional statements which are decision making statements. Life is full of conditions. If you complete your homework, your mum will let you play, if you don’t, she will scold you.

Mostly we use relational operators for putting conditions in the conditional statements like: Equal to(=), Greater than (>), Less than (<), Less than or equal to (<=). 

Types

Conditional statements are basically of two types:

1. If-then

If-statement contains one condition and one statement. If the condition holds true, the statement will execute. If not you will not get anything

2. If-then else

This contains one condition and two statements. If the condition holds true the first statement will execute, if not the second one will execute.

Apart from these conditional statements we use some more conditional statements like if we have to put multiple conditions and conditions inside a condition.

Ladder-if

Ladder-if is used to execute a specific block of code if a condition is true, and another block of code if a different condition is true.

Nested-if

Condition inside a condition is called Nested-if.

Loops in Python

Loops are fundamental programming constructs that allow you to execute a block of code repeatedly. Python provides two main types of loops:

for Loop

Used for iterating over sequences (lists, tuples, strings, etc.) or a fixed number of times.

while Loop

Execute as long as a condition is true.

Activity 1

What is Factorial Number?

The factorial of a number is the product of all positive integers less than or equal to that number.

Code

Activity 2

What is Prime number?

A natural number that is greater than 1, but not divisible by 1, is called a prime number. In other words, a prime number is only divisible by 1 and itself without leaving a remainder. 

Code

Activity 3

How to draw different star patterns using loops?

Star patterns can be created using nested loops in Python. The outer loop controls the number of rows, and the inner loop controls the number of stars in each row.

  • Right-Angled Triangle

  • Inverted Right-Angled Triangle

Outcome

  • Learners can write and run Python programs.
  • Understand and implement basic loops and conditions.
  • Analyze problem statements and write code logic.
  • Apply programming fundamentals to solve simple problems.

Observations

  • How students interact with the editor (IDLE/VS Code).
  • Ability to identify syntax and logic errors.
  • Improvement in writing structured and error-free code.

 
0 0

There are no comments for now.

to be the first to leave a comment.