Unit 3: Python Programming Selection Statements Part 2 – AI Made Easy for Class 11 CBSE 2025

Posted by


In this tutorial, we will continue our discussion on Selection Statements in Python programming. We will cover the concepts of Nested Selection Statements and the use of Logical Operators in making complex decisions in programs.

Nested Selection Statements:

Nested selection statements are used when we need to make multiple decisions based on multiple conditions. In Python, we can nest if-else statements within another if-else statement to handle such situations. The syntax for a nested selection statement is as follows:

if condition1:
    if condition2:
        # code to be executed if condition1 and condition2 are true
    else:
        # code to be executed if condition1 is true but condition2 is false
else:
    # code to be executed if condition1 is false

Let’s understand this with an example:

x = 10
if x > 0:
    if x % 2 == 0:
        print("x is a positive even number")
    else:
        print("x is a positive odd number")
else:
    print("x is not a positive number")

In this example, if x is greater than 0, we check if it is even or odd, and if it is not positive, we print that it is not a positive number. This is an example of a nested selection statement.

Logical Operators:

Logical operators are used to combine multiple conditions in a selection statement. Python supports three logical operators: and, or, and not. These operators are used to check if two or more conditions are true, or to reverse the result of a condition. The logical operators work as follows:

  • and: Returns True if both conditions are true
  • or: Returns True if at least one of the conditions is true
  • not: Returns the opposite of the condition

Let’s see how logical operators can be used in a selection statement:

x = 10
y = 5

if x > 0 and y > 0:
    print("Both x and y are positive")

if x > 0 or y > 0:
    print("At least one of x or y is positive")

if not(x < 0):
    print("x is not negative")

In this example, we use the logical operators to check if both x and y are positive, at least one of them is positive, and if x is not negative.

With the knowledge of nested selection statements and logical operators, you can now make more complex decisions in your Python programs. Practice writing and executing programs using these concepts to reinforce your understanding.

That’s all for this tutorial on Selection Statements in Python. Stay tuned for more tutorials on Python programming!

0 0 votes
Article Rating

Leave a Reply

17 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@tanmaysachdev426
2 hours ago

Sir please make a video on capstone project and data literacy.
And on Employability skills also

@shreyanshtiwari8394
2 hours ago

Sirr , plz bring importance ip practical for 11th ip , i have done syallbus for my half yearly with your chaneel but troubling with questions and practical

@prathamarora1168
2 hours ago

love your videos

@Avika-uw9be
2 hours ago

👍👍

@RonavJindal
2 hours ago

Hello sir , please make a video on your JEE Journey ! 😍♥

@Harshitha_Jawahar
2 hours ago

Hi bhaiya! For grade 10 the syllabus has changed from open office to libreoffice ..pls upload the updated syllabus video pls bhaiya

@JyotiSharma-ov8xs
2 hours ago

sir from where r u belong and what course did u do after 12th?

@JustARandomChannel-e6q
2 hours ago

Hello sir, pls make a video on data storytelling for AI 843 class 12
You really helped me a lot in class 10 IT and 11 AI.
I want just this chapter's video so that my ai syllabus gets finished.
Hope you will make it soon.

@romyalex180
2 hours ago

Pls upload IP class also it was very helpful

@artdiary5690
2 hours ago

Sir did computer science students can watch this video for python

@ANURAG-IITIAN
2 hours ago

bhaiya please make sep video for JEE Preperation please please !!!! Jee aspirant like

@charan2621
2 hours ago

bro please teach for class 11 Computer Science from Sumita Arora book 🙏 Code 083

@harshpreetsingh1408
2 hours ago

Thanks

@PriyanshuSrivastava-cu2kt
2 hours ago

Sir plss class 12 CS Python ke liye bhi videos daliya nah sir plsss
Sir 10 me apse padh kr 99 aaye the
Sir plss uski videos bhi upload kr dijiye
SQL wali unit sbse pehle kr dijiyega plss sir❤

@Nike-whey
2 hours ago

Bhaiya ye sab toh mast hai but IIT jane ki kutch tips de do plz

@PrachiBaranwal-qv8vr
2 hours ago

Bhaiya pls make a detailed video on TUPLE Also

@nitika9770
2 hours ago

Hello sir
I really want to thank you.. You helped me so much in my class 10 .. Thank you sir😊

17
0
Would love your thoughts, please comment.x
()
x