SlideShare a Scribd company logo
1 of 16
Python Flow Control
Class: XI
Computer Science-083
Introduction
Part-1
Python Flow Of Control
A program’s control flow is the order in which the program’s code executes. A Flow
Control Statement defines the flow of the execution of the Program. Control flow
statements are required to alter the flow of program execution based on the
conditions.
SEQUENTIAL :
SELECTION CONDITIONAL:
ITERATIVE / LOOPING:
It is classified into three categories:
Python Flow Of Control
SEQUENTIAL :
It to provide the order in which we execute our instructions.
Example: Program to display sum of two numbers.
A=10
B=12
sum=A+B
print(sum)
All the lines are in a
sequence
Python Flow Of Control
Decision-making statements : if, if..else, if..elif..else
SELECTION CONDITIONAL: Selection to allow decisions to be made.
Python Flow Of Control
Looping statements : for, while
Branching statements : break, continue
ITERATIVE / LOOPING:
Iteration to loop or repeat our instructions as many times as we
need.
Decision-making Statements or Conditional Statements
if Statement
if - else Statement
elif statements
The if statement is used to test a specific condition. If the condition is true, a block of
code or block of statements will be executed.
The if-else statement is similar to if statement except that, it also provides the block of
the code for the false case of the condition to be checked. If the condition provided in
the if statement is false, then the else statement will be executed.
In python, we have one more conditional statement called elif statements. elif
statement is used to check multiple conditions only if the given if condition false. It’s
similar to an if-else statement and the only difference is that in else we will not check
the condition but in elif we will do check the condition.
Nested if-else statements
Nested if-else statements mean that an if statement or if-else statement is present inside
another if or if-else block. Python provides this feature as well, this in turn will help us to
check multiple conditions in a given program.
elif Ladder
It means a program which contains ladder of elif statements or elif statements which are
structured in the form of a ladder.
This statement is used to test multiple expressions
What is for loop in Python?
Python Loops or Iteration
for loops
There are two types of loops in Python
Loops can execute a block of code number of times until a certain condition is met.
while loops While Loop is used to repeat a block of code. Instead of running the
code block once, It executes the code block multiple times until a
certain condition is met
In Python, "for loops" are called iterators.ust like while loop, "For Loop"
is also used to repeat the program. But unlike while loop which
depends on condition true or false. "For Loop" depends on the
elements it has to iterate
So first we discuss Decision-making Statements
if Statement
if - else Statement
elif statements
Nested if-else statements
elif Ladder
if Statement
The if statement is used to test a specific condition. If the condition is true only, a block
of code or block of statements will be executed.
Syntax:
if condition or expression:
-----Statements-------
-----Statements-------
Example: Program to check number is less than 10 , if yes
then display message "Number is smaller than 10"
no=5
If no<10:
print(“Number is smaller than 10”)
---Output----
Number is smaller than 10
This is indentation. Python relies on indentation (whitespace
at the beginning of a line) to define scope in the code
Let us understand the if condition indentation and scope with the help of another example:
Num = 5
if(Num < 10):
print(“Num is smaller than 10”)
print(“This statements will always be executed”)
---Output----
Number is smaller than 10
This statements will always be executed
Num = 15
if(Num < 10):
print(“Num is smaller than 10”)
print(“This statements will always be executed”)
---Output----
This statements will always be executed
Now in this case if we change the value of Num to 15, then if() condition not satisfied and
it not run the statement inside its scope , but last message will display it is because it not a
part of if condition , its out of its scope.
So in python indentation is very important to get a correct result.
If statement, without indentation (will raise an error)
a = 33
b = 200
if b > a:
print("b is greater than a")
For example , if we need to check that variable A is greater than B.
It display the error message , that
indentation missing.
a = 33
b = 200
if b > a:
print("b is greater than a")
Correct code is when we use proper indentation:
---Output----
B is greater than a
So now we know python indentation
Let take one more example: Write a program to accept the age of a person and check the
age is more than equal to 18, if yes than display ‘You are valid to vote’
age=int(input(“Enter the age:”))
if age>=18:
print(‘You are valid to vote’)
---Output----
Enter the age: 19
You are valid to vote
Now we use the logical operator AND , OR with if condition
OR with if condition:
Now if you want to display message “You select write number” if a user enter any one
number from the given list and the numbers are 1, 3, 5
no=int(input(“Enter the value[1 , 3 , 5]:”))
if (no==1 or no==3 or no == 5):
print(“You selected write number”)
---Output----
Enter the value[1,3,5]: 5
You selected write number
Now we use the logical operator AND , OR with if condition
AND with if condition:
Write a program to check the number is between 10 to 40 , if yes then print message that
“Your value in range of 10-40”
no=int(input(“Enter the value:”))
if (no>=10 and no<=40):
print(“You value in range of 10-40”)
---Output----
Enter the value: 15
Your value in range of 10-40
One important point the And is used for checking the range values. For Example:
How to use if’s without else part in a program
If’s condition:
Write a program to accept a number and print the following message:
If no is 1 “you selected 1” , if no is 2 “you selected 2” , if no is 3 “you selected 3”
no=int(input(“Enter the value:”))
if (no == 1):
print(“You selected 1”) ---Output----
Enter the value: 2
Your selected 2
if (no == 2):
print(“You selected 2”)
if (no == 3):
print(“You selected 3”)

More Related Content

What's hot

What's hot (20)

Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion | Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Python
PythonPython
Python
 
Basics of python
Basics of pythonBasics of python
Basics of python
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 

Similar to FLOW OF CONTROL-INTRO PYTHON

conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
sdvdsvsdvsvds
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
XhelalSpahiu
 

Similar to FLOW OF CONTROL-INTRO PYTHON (20)

Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
loops.pdf
loops.pdfloops.pdf
loops.pdf
 
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
control statements in python.pptx
control statements in python.pptxcontrol statements in python.pptx
control statements in python.pptx
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
 
PRESENTATION.pptx
PRESENTATION.pptxPRESENTATION.pptx
PRESENTATION.pptx
 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
 
python 34💭.pdf
python 34💭.pdfpython 34💭.pdf
python 34💭.pdf
 
controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docx
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdf
 
Python session3
Python session3Python session3
Python session3
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 

More from vikram mahendra

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 
Entrepreneurial skills
Entrepreneurial skillsEntrepreneurial skills
Entrepreneurial skills
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

FLOW OF CONTROL-INTRO PYTHON

  • 1. Python Flow Control Class: XI Computer Science-083 Introduction Part-1
  • 2. Python Flow Of Control A program’s control flow is the order in which the program’s code executes. A Flow Control Statement defines the flow of the execution of the Program. Control flow statements are required to alter the flow of program execution based on the conditions. SEQUENTIAL : SELECTION CONDITIONAL: ITERATIVE / LOOPING: It is classified into three categories:
  • 3. Python Flow Of Control SEQUENTIAL : It to provide the order in which we execute our instructions. Example: Program to display sum of two numbers. A=10 B=12 sum=A+B print(sum) All the lines are in a sequence
  • 4. Python Flow Of Control Decision-making statements : if, if..else, if..elif..else SELECTION CONDITIONAL: Selection to allow decisions to be made.
  • 5. Python Flow Of Control Looping statements : for, while Branching statements : break, continue ITERATIVE / LOOPING: Iteration to loop or repeat our instructions as many times as we need.
  • 6. Decision-making Statements or Conditional Statements if Statement if - else Statement elif statements The if statement is used to test a specific condition. If the condition is true, a block of code or block of statements will be executed. The if-else statement is similar to if statement except that, it also provides the block of the code for the false case of the condition to be checked. If the condition provided in the if statement is false, then the else statement will be executed. In python, we have one more conditional statement called elif statements. elif statement is used to check multiple conditions only if the given if condition false. It’s similar to an if-else statement and the only difference is that in else we will not check the condition but in elif we will do check the condition.
  • 7. Nested if-else statements Nested if-else statements mean that an if statement or if-else statement is present inside another if or if-else block. Python provides this feature as well, this in turn will help us to check multiple conditions in a given program. elif Ladder It means a program which contains ladder of elif statements or elif statements which are structured in the form of a ladder. This statement is used to test multiple expressions
  • 8. What is for loop in Python? Python Loops or Iteration for loops There are two types of loops in Python Loops can execute a block of code number of times until a certain condition is met. while loops While Loop is used to repeat a block of code. Instead of running the code block once, It executes the code block multiple times until a certain condition is met In Python, "for loops" are called iterators.ust like while loop, "For Loop" is also used to repeat the program. But unlike while loop which depends on condition true or false. "For Loop" depends on the elements it has to iterate
  • 9. So first we discuss Decision-making Statements if Statement if - else Statement elif statements Nested if-else statements elif Ladder
  • 10. if Statement The if statement is used to test a specific condition. If the condition is true only, a block of code or block of statements will be executed. Syntax: if condition or expression: -----Statements------- -----Statements------- Example: Program to check number is less than 10 , if yes then display message "Number is smaller than 10" no=5 If no<10: print(“Number is smaller than 10”) ---Output---- Number is smaller than 10 This is indentation. Python relies on indentation (whitespace at the beginning of a line) to define scope in the code
  • 11. Let us understand the if condition indentation and scope with the help of another example: Num = 5 if(Num < 10): print(“Num is smaller than 10”) print(“This statements will always be executed”) ---Output---- Number is smaller than 10 This statements will always be executed Num = 15 if(Num < 10): print(“Num is smaller than 10”) print(“This statements will always be executed”) ---Output---- This statements will always be executed Now in this case if we change the value of Num to 15, then if() condition not satisfied and it not run the statement inside its scope , but last message will display it is because it not a part of if condition , its out of its scope.
  • 12. So in python indentation is very important to get a correct result. If statement, without indentation (will raise an error) a = 33 b = 200 if b > a: print("b is greater than a") For example , if we need to check that variable A is greater than B. It display the error message , that indentation missing. a = 33 b = 200 if b > a: print("b is greater than a") Correct code is when we use proper indentation: ---Output---- B is greater than a
  • 13. So now we know python indentation Let take one more example: Write a program to accept the age of a person and check the age is more than equal to 18, if yes than display ‘You are valid to vote’ age=int(input(“Enter the age:”)) if age>=18: print(‘You are valid to vote’) ---Output---- Enter the age: 19 You are valid to vote
  • 14. Now we use the logical operator AND , OR with if condition OR with if condition: Now if you want to display message “You select write number” if a user enter any one number from the given list and the numbers are 1, 3, 5 no=int(input(“Enter the value[1 , 3 , 5]:”)) if (no==1 or no==3 or no == 5): print(“You selected write number”) ---Output---- Enter the value[1,3,5]: 5 You selected write number
  • 15. Now we use the logical operator AND , OR with if condition AND with if condition: Write a program to check the number is between 10 to 40 , if yes then print message that “Your value in range of 10-40” no=int(input(“Enter the value:”)) if (no>=10 and no<=40): print(“You value in range of 10-40”) ---Output---- Enter the value: 15 Your value in range of 10-40 One important point the And is used for checking the range values. For Example:
  • 16. How to use if’s without else part in a program If’s condition: Write a program to accept a number and print the following message: If no is 1 “you selected 1” , if no is 2 “you selected 2” , if no is 3 “you selected 3” no=int(input(“Enter the value:”)) if (no == 1): print(“You selected 1”) ---Output---- Enter the value: 2 Your selected 2 if (no == 2): print(“You selected 2”) if (no == 3): print(“You selected 3”)