0% found this document useful (0 votes)
2 views36 pages

python1

The document outlines a comprehensive introduction to programming, focusing on Python, its features, and basic syntax. It covers topics such as Python's history, advantages, drawbacks, installation, and practical demonstrations of programming concepts including variables, data types, operators, and decision-making structures. The document also includes student activities, learning outcomes, and frequently asked questions to reinforce understanding of Python programming.

Uploaded by

bahinki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views36 pages

python1

The document outlines a comprehensive introduction to programming, focusing on Python, its features, and basic syntax. It covers topics such as Python's history, advantages, drawbacks, installation, and practical demonstrations of programming concepts including variables, data types, operators, and decision-making structures. The document also includes student activities, learning outcomes, and frequently asked questions to reinforce understanding of Python programming.

Uploaded by

bahinki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Part 1: Introduction to Programming (5 Minutes)

Ask students:

1. What is a programming language?

2. Name some programming languages.

3. Why do we need programming?

Expected Answers:

• Programming language is used to communicate with computers.

• Examples:

o C

o C++

o Java

o Python

Part 2: What is Python? (10 Minutes)

Definition

Python is a high-level, interpreted, general-purpose programming language developed by


Guido van Rossum in 1991.

Board Work

Python

High Level Language

Easy to Learn

Interpreted Language

Object Oriented

PYQ
What is Python? What are its advantages and drawbacks?

Asked in June 2024.

History of Python

Year Event

1989 Development Started

1991 First Release

Developer Guido van Rossum

PYQ

Who is the developer of Python?

Answer:
Guido van Rossum

Features of Python (10 Minutes)

1. Easy to Learn

print("Hello")

Only one line required.

2. Interpreted Language

No compilation required.

3. Open Source

Free to use.

4. Portable

Runs on:

• Windows

• Linux
• Mac

5. Object Oriented

Supports classes and objects.

6. Large Library Support

Modules available:

• math

• sys

• time

Advantages of Python

1. Easy syntax

2. Readable code

3. Open source

4. Portable

5. Huge library support

Drawbacks of Python

1. Slower than C/C++

2. More memory consumption

3. Not preferred for mobile apps

Part 3: Python Versions (5 Minutes)

Python 2

Old version

Example:

print "Hello"
Python 3

Current version

Example:

print("Hello")

Part 4: Installing Python (5 Minutes)

Demonstration

Visit:

Python official website

Install latest Python 3.x

During installation:

Tick

Add Python to PATH

Part 5: IDLE (10 Minutes)

Definition

IDLE stands for:

Integrated Development and Learning Environment

PYQ

Define IDLE.

Asked in June 2024.

Two Modes of Python

1. Interactive Mode

>>> 10+20

30

Result appears immediately.


2. Script Mode

Create file:

[Link]

Write:

print("Hello World")

Save and Run.

Practical Demonstration (10 Minutes)

Program 1

print("Hello World")

Output

Hello World

Program 2

print("Welcome to Python")

Output

Welcome to Python

Program 3

print("Government Polytechnic")

Output

Government Polytechnic

Program 4

print("Name : Aman")

print("Roll No : 101")

print("Branch : CSE")
Output

Name : Aman

Roll No : 101

Branch : CSE

Student Lab Activity

Ask every student to create:

print("My Name is ______")

print("My Roll Number is ______")

print("I am learning Python")

Run successfully.

Learning Outcomes

After this lecture students will be able to:

• Understand Python syntax

• Use comments

• Create variables

• Identify data types

• Use type() function

• Understand dynamic typing

• Perform type casting

PYQs Covered Today

From Dec'22, Jun'24, Nov'24:

• Define Variable

• Define Data Type

• Which function is used to get type of variable?


• Write numeric data types used in Python

• Define Type Casting

• Comments in Python

• Python Variables

• Python Data Types

Part 1: Basic Python Syntax (10 Minutes)

Rules

1. Python is case sensitive

name = "Aman"

Name = "Rahul"

print(name)

print(Name)

Output

Aman

Rahul

Explain:
name and Name are different variables.

PYQ

Python is not a case sensitive language (T/F)

Answer: False

Indentation

Python uses indentation instead of braces.

Correct:

if 10 > 5:

print("True")
Wrong:

if 10 > 5:

print("True")

Part 2: Comments (10 Minutes)

Single Line Comment

# This is a comment

print("Hello")

Multi-line Comment

"""

This is

multi-line

comment

"""

PYQ

Which symbol is used to write comments in Python?

Answer:

Part 3: Variables (10 Minutes)

Definition

A variable is a named memory location used to store data.

Example

name = "Aman"

age = 18

print(name)

print(age)
Board Work

Variable

Stores Data

Can Change During Program

PYQ

Define Variable

Variable Naming Rules

Valid

name

student_name

age1

Invalid

1name

student-name

class

Part 4: Data Types (10 Minutes)

Definition

Data Type specifies the type of value stored in a variable.

Integer

a = 10

Float

b = 12.5
String

name = "Aman"

Boolean

status = True

Complex

x = 3+4j

PYQ

Write numeric data types used in Python.

Answer:

• int

• float

• complex

type() Function

Syntax

type(variable)

Example

a = 10

print(type(a))

Output

<class 'int'>

PYQ

Which function is used to get type of variable?


Answer:

type()

Part 5: Dynamic Typing (5 Minutes)

Python is dynamically typed.

Example:

x = 10

print(x)

x = "Hello"

print(x)

Output

10

Hello

Same variable can store different data types.

Part 6: Type Casting (5 Minutes)

Definition

Conversion of one data type into another.

Example

a = "10"

b = int(a)

print(b)

Output
10

Common Type Casting

int()

float()

str()

PYQ

Define Type Casting

Answer:
Conversion of one data type into another data type.

Practical Demonstration

Program 1

name = "Aman"

print(name)

Program 2

age = 18

print(type(age))

Program 3

salary = 25000.50

print(type(salary))

Program 4

x = 10
print(type(x))

x = "Python"

print(type(x))

Program 5

a = "100"

b = int(a)

print(b)

print(type(b))

Student Lab Activity

Activity 1

Create variables:

name = "Your Name"

roll = 101

marks = 85.5

Print all variables.

Activity 2

Check type of variables using:

type()

Activity 3
Convert:

"50"

into integer.

After this lecture students will be able to:

• Define operators

• Use arithmetic operators

• Use relational operators

• Use logical operators

• Use assignment operators

• Use membership operators

• Use identity operators

• Solve PYQ-based programs

PYQs Covered Today

From uploaded papers:

• Explain operators used in Python.

• What is membership operator?

• What is identity operator?

• Which operator is used for concatenation?

• Differentiate relational and logical operators.

These are frequently repeated.

Part 1: Introduction to Operators (5 Minutes)

Definition

An operator is a symbol used to perform an operation on variables and values.

Example:
a = 10

b=5

print(a + b)

Output:

15

Here + is an operator.

Part 2: Arithmetic Operators (10 Minutes)

Used for mathematical calculations.

Operator Meaning Example

+ Addition 10+5

- Subtraction 10-5

* Multiplication 10*5

/ Division 10/5

% Modulus 10%3

// Floor Division 10//3

** Power 2**3

Example

a = 10

b=3

print(a+b)

print(a-b)

print(a*b)

print(a/b)

print(a%b)
print(a//b)

print(a**b)

Practical Activity 1

Calculator Program

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

print("Addition =", a+b)

print("Subtraction =", a-b)

print("Multiplication =", a*b)

print("Division =", a/b)

Part 3: Relational Operators (10 Minutes)

Used to compare values.

Operator Meaning

== Equal

!= Not Equal

> Greater Than

< Less Than

>= Greater Than Equal

<= Less Than Equal

Example

a = 10

b = 20

print(a==b)
print(a!=b)

print(a>b)

print(a<b)

Output:

False

True

False

True

PYQ

>= is an example of which operator?

Answer:
Relational Operator

Part 4: Logical Operators (10 Minutes)

Used to combine conditions.

Operator Meaning

and Both conditions true

or Any condition true

not Reverse result

Example

a = 10

b = 20

print(a>5 and b>10)

Output:

True

Example 2
print(True or False)

Output:

True

Example 3

print(not True)

Output:

False

Part 5: Assignment Operators (5 Minutes)

Operator Example

= x=10

+= x+=5

-= x-=5

*= x*=2

/= x/=2

Example

x = 10

x += 5

print(x)

Output:

15

Part 6: Membership Operators (5 Minutes)

PYQ
What is Membership Operator?

Used to check whether a value exists in a sequence.

Operators:

in

not in

Example

name = "python"

print("p" in name)

Output:

True

Example

name = "python"

print("z" in name)

Output:

False

Part 7: Identity Operators (5 Minutes)

PYQ

What is Identity Operator?

Used to compare memory location.

Operators:

is

is not

Example

x = 10
y = 10

print(x is y)

Output:

True

Part 8: String Concatenation

PYQ

Which operator is used for string concatenation?

Answer:

Example:

first = "Hello"

second = "World"

print(first + second)

Output:

HelloWorld

Practical Demonstration

Program 1

a = 20

b = 10

print(a+b)

print(a-b)

print(a*b)

print(a/b)
Program 2

a = 50

b = 30

print(a>b)

print(a<b)

Program 3

print(True and True)

print(True and False)

Program 4

name = "Punjab"

print("P" in name)

Program 5

x = 10

y = 10

print(x is y)

Student Lab Activity

Activity 1

Create calculator program.

Activity 2

Check whether:
"A" in "AMAN"

Activity 3

Use:

and

or

not

operators and observe results.

After this lecture students will be able to:

• Take input from user

• Display output

• Understand string values

• Use common string methods

• Write simple string manipulation programs

Syllabus Coverage

String Values
String Methods
Basic Python Syntax Revision

PYQs Covered Today

From previous papers:

• What is a String?

• Explain String Methods.

• Write a program using input().

• Differentiate input and output.

Part 1: Input and Output Functions (10 Minutes)


Output Function

Used to display output on screen.

Syntax

print("Hello")

Example

print("Welcome to Python")

Output

Welcome to Python

Input Function

Used to take input from user.

Syntax

input()

Example

name = input("Enter Name: ")

print(name)

Sample Output

Enter Name: Aman

Aman

Practical Demo 1

name = input("Enter Your Name: ")

print("Welcome", name)

Practical Demo 2

college = input("Enter College Name: ")


print(college)

Part 2: String Values (10 Minutes)

Definition

A string is a collection of characters enclosed in quotes.

Examples

name = "Aman"

city = "Hoshiarpur"

Single Quotes

name = 'Python'

Double Quotes

name = "Python"

Triple Quotes

message = """Welcome

to

Python"""

PYQ

What is a String?

Answer:

A string is a sequence of characters enclosed in single, double or triple quotes.

Part 3: String Operations (10 Minutes)

Concatenation
Joining strings.

first = "Hello"

second = "World"

print(first + second)

Output

HelloWorld

Repetition

print("Python"*3)

Output

PythonPythonPython

Length of String

name = "Punjab"

print(len(name))

Output

Part 4: String Methods (15 Minutes)

upper()

Converts to uppercase.

name = "python"

print([Link]())

Output

PYTHON
lower()

Converts to lowercase.

name = "PYTHON"

print([Link]())

Output

python

title()

name = "computer engineering"

print([Link]())

Output

Computer Engineering

replace()

text = "I like Java"

print([Link]("Java","Python"))

Output

I like Python

find()

name = "Punjab"

print([Link]("j"))

Output
3

count()

text = "banana"

print([Link]("a"))

Output

strip()

Removes extra spaces.

name = " Aman "

print([Link]())

Output

Aman

Practical Demonstration

Program 1

name = input("Enter Name: ")

print([Link]())

Program 2

city = input("Enter City: ")

print([Link]())
Program 3

text = "Government Polytechnic"

print(len(text))

Program 4

name = "python programming"

print([Link]())

Program 5

fruit = "banana"

print([Link]("a"))

Student Lab Activity

Activity 1

Take student name as input and display it in uppercase.

name = input("Enter Name: ")

print([Link]())

Activity 2

Find length of your college name.

college = input("Enter College Name: ")

print(len(college))
Activity 3

Replace one word in a sentence.

Example:

sentence = "I like Cricket"

print([Link]("Cricket","Python"))

Viva Questions

1. What is a string?

2. Which function is used for input?

3. Which function is used for output?

4. What is string concatenation?

5. What does upper() do?

6. What does lower() do?

7. What does len() return?

8. What is replace() method?

9. What is count() method?

10. What is find() method?

Important Exam Questions

1 Mark

• Define String.

• Which function is used to take input?

• Which function is used to display output?

• What does upper() method do?

5 Marks

• Explain String Methods with examples.

• Explain input() and print() functions.


• Explain String operations with examples.

PYQs Covered Today

Repeated in PSBTE:

• Explain if statement with syntax.

• Write a program to check whether a number is positive.

• Write a program to determine whether a student has passed.

• Explain decision making in Python.

Part 1: Introduction to Decision Making (10 Minutes)

Ask students:

Real-Life Examples

1. If it rains, carry an umbrella.

2. If marks > 40, student passes.

3. If age ≥ 18, eligible to vote.

Computer programs also make decisions.

What is Decision Making?

Decision making means choosing an action based on a condition.

Example:

If condition is True

Execute statement

Otherwise

Skip statement

Part 2: IF Statement (10 Minutes)

Syntax
if condition:

statement

Flow

Condition

True ?

Execute Statement

Example 1

age = 20

if age >= 18:

print("Eligible to Vote")

Output

Eligible to Vote

Understanding Indentation

Correct:

if 10 > 5:

print("True")

Wrong:

if 10 > 5:

print("True")

Python gives error.

Example 2
marks = 75

if marks >= 40:

print("Pass")

Output

Pass

Part 3: Using User Input with IF (10 Minutes)

age = int(input("Enter Age: "))

if age >= 18:

print("Eligible for Voting")

Discussion

Input = 20

Output

Eligible for Voting

Input = 15

Output

(No output)

Because condition is False.

Practical Program 1

Positive Number Program

PYQ Type

num = int(input("Enter Number: "))

if num > 0:
print("Positive Number")

Sample Output

Input

25

Output

Positive Number

Practical Program 2

Pass Program

marks = int(input("Enter Marks: "))

if marks >= 40:

print("Pass")

Practical Program 3

Voting Eligibility

age = int(input("Enter Age: "))

if age >= 18:

print("Eligible")

Practical Program 4

Check Even Number

num = int(input("Enter Number: "))

if num % 2 == 0:

print("Even Number")
Practical Program 5

Check Divisibility by 5

num = int(input("Enter Number: "))

if num % 5 == 0:

print("Divisible by 5")

Classroom Activity

Ask students to predict output.

Program A

x = 10

if x > 5:

print("Hello")

Output?

Answer:

Hello

Program B

x=2

if x > 5:

print("Hello")

Output?

Answer:

No Output
Student Lab Activity

Activity 1

Create program to check:

marks >= 33

Print:

Pass

Activity 2

Check:

salary > 50000

Print:

High Salary

Activity 3

Check:

temperature > 30

Print:

Hot Day

Viva Questions

1. What is decision making?

2. What is if statement?

3. What is syntax of if statement?

4. Why is indentation important?

5. What happens if condition becomes False?

6. Which operator is used in conditions?

7. Can multiple statements exist inside if?

8. What is relational operator?


9. Can input() be used with if?

10. What is the purpose of decision making?

Important Exam Questions

1 Mark

• Define if statement.

• What is decision making?

• Why is indentation important in Python?

5 Marks

• Explain if statement with syntax and example.

• Write a program to check whether a number is positive.

• Write a program to determine voting eligibility.

You might also like