Notes_Class_10_Python02_Conditional_Statements.pptx

samirparmar24 0 views 21 slides Oct 16, 2025
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

python


Slide Content

PART B UNIT 3 ADVANCED PYTHON

CONDITIONAL STATEMENTS

RELATIONAL OPERATORs IN PYTHON Before we go to conditional statements we would need to understand Relational Operators in python and learn how they work.

CONDITIONAL STATEMENT In Python we use different conditional statements to put condition on the flow of program and control the flow of program. For right now let’s see simple ‘if’ conditions Simple ‘if’ statement can be used to do decision making

IF STATEMENTS IN PYTHON It is very easy to write ‘if’ statements in python Syntax if <condition>: statement1 statement 2 One thing we have to keep in mind while writing ‘if’ statement is that we have to keep indent while we are writing statements inside ‘if’ statements.

EXAMPLE

IF ELSE STATEMENT IN PYTHON 'If ..else’ evaluates test expression and will execute the body of if only when the test condition is True. If the condition is False, the body of else is executed. Indentation is used to separate the blocks. Syntax: if <condition>: statements… else: statements…

EXAMPLE

IF..ELIF..ELSE STATEMENTS IN PYTHON The elif is short for else if. It allows us to check for multiple expressions. If the condition for if is False, it checks the condition of the next elif block and so on. If all the conditions are False, the body of else is executed. Only one block among the several if... elif ...else blocks is executed according to the condition. The if block can have only one else block. But it can have multiple elif blocks.

SYNTAX If <condition>: statement/s (for true condition) elif <condition>: statement/s (for true condition) …. else: statement/s

EXAMPLE

NESTED IF STATEMENTS We can have a if... elif ...else statement inside another if... elif ...else statement. This is called nesting in computer programming. Any number of these statements can be nested inside one another. Indentation is the only way to figure out the level of nesting.

SYNTAX if <condition>: if <condition>: statement else: statement else: statement

EXAMPLE

Sample Programs # 1 WAP to compare 2 numbers n1=int(input(“Enter first number-:”)) n2=int(input(“Enter second number-:”)) if n1>n2: print(n1, “is larger”) else: print(n2, “is larger”)

Sample Programs # 2 WAP to decide whether the given number is odd or even no=int(input(“Enter a number-:”)) if no % 2==0: print(no, “is even”) else: print(no, “is odd”)

Sample Programs # 3 WAP to decide whether the given year is leap year or not year=int(input(“Enter year in yyyy format-:”)) if year % 4==0: print(no, “is even”) else: print(no, “is odd”)

Sample Programs # 4 WAP to decide whether the given number is + ve or – ve no=int(input(“Enter a number-:”)) if no < 0: print(no, “is - ve ”) else: print(no, “is + ve ”)

Sample Programs # 5 WAP to decide whether the student is passing or not mark=int(input(“Enter the aggregate %-:”)) if mark < 33: print(“Student is failing”) else: print (“Student is passing”)

Sample Programs # 6 WAP to decide whether the shopkeeper is getting profit or loss on selling a product. Display profit/loss cp=float(input(“Cost price of the product:”)) sp =float(input(“Selling price of the product:”)) if cp> sp print(“Shopkeeper is getting loss”) print(“Loss= ”,cp- sp ) else: print(“Shopkeeper is getting profit”) print(“Profit= ”, sp -cp)
Tags