SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Python Flow Control
Class: XI
Computer Science-083
If..else conditions
Part-2
if .. else Statement
The if ..else.. statement is used to test a specific condition. If the condition is true , a
block of code or block of statements will be executed, otherwise false section statement
will be executed
Syntax:
if condition or expression:
-----Statements-------
-----Statements-------
else:
-----Statements-------
-----Statements-------
This is True
part of if
condition
This is False
part of if
condition
Let us understand how the if..else work
F the question is to check the user input age is more than equal to 18 or not, if yes
than display “Valid to Vote” , otherwise display “Not valid to vote”
age=int(input(“Enter the age:”))
if (age>=18):
print(“Valid to vote”)
print(“Valid to vote”)
else:
Enter the age: 20
Valid to vote
If the condition is TRUE
If the condition is False
Let us understand how the if..else work
Program to accept number from user and check that number is positive or
negative.
no=int(input(“Enter the no:”))
if (no>0):
print(“It’s a positive value”)
print(“It’s a negative value”)
else:
Enter the no: -9
It’s a negative value
Let us understand how the if..else work
Program to accept number from user and check that number is even or
odd.
no=int(input(“Enter the no:”))
if (no%2==0):
print(“It’s a Even number”)
print(“It’s a Odd number”)
else:
Enter the no: 5
It’s a Odd number
Enter the no: 2
It’s a Even number
Let us understand how the if..else work
Program to accept number from user and check that number is divisible by
3 or 7 or not
no=int(input(“Enter the no:”))
if (no%3==0 or no%7==0):
print(“Number is divisible by 3 or 7”)
print(“Number is not divisible by 3 or 7”)
else:
Enter the no: 15
Number is divisible by 3 or 7
Let us understand how the if..else work
Program to accept year from user and check that year is a leap year or not.
Example : year is leap year if it is divisible by 4 or 400 or 100
yy=int(input(“Enter the year:”))
if (yy%4==0 or yy%400==0 or yy%100!=0):
print(“It’s a leap year”)
print(“Its not a leap year”)
else:
Enter the year:2005
A year is said to be leap year, if the year is exactly divisible by 4 but and not
divisible by 100. Year is also a leap year if it is exactly divisible by 400.
Let us understand how the if..else work
Program to accept number and find maximum between two numbers
a=int(input(“Enter the value a:”))
if (a>b):
print(“A greater than B”)
print(“B is greater than A”)
else:
Enter the value a: 5
Enter the value b: 2
A is greater than B
b=int(input(“Enter the value b:”))

Weitere ähnliche Inhalte

Was ist angesagt?

04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
Jomel Penalba
 

Was ist angesagt? (19)

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
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Assignment7
Assignment7Assignment7
Assignment7
 
Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Visula C# Programming Lecture 4
Visula C# Programming Lecture 4
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 
Programming egs
Programming egs Programming egs
Programming egs
 
04 control structures 1
04 control structures 104 control structures 1
04 control structures 1
 
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]
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
C programming part4
C programming part4C programming part4
C programming part4
 

Ähnlich wie FLOWOFCONTROL-IF..ELSE PYTHON

conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
sdvdsvsdvsvds
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
alish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
alish sha
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
Karwan Mustafa Kareem
 

Ähnlich wie FLOWOFCONTROL-IF..ELSE PYTHON (20)

conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdfconditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
conditionalanddvfvdfvdvdcontrolstatement-171023101126.pdf
 
Ch4
Ch4Ch4
Ch4
 
loops.pdf
loops.pdfloops.pdf
loops.pdf
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
 
Java Programmin: Selections
Java Programmin: SelectionsJava Programmin: Selections
Java Programmin: Selections
 
Conditional-Statement.pdf
Conditional-Statement.pdfConditional-Statement.pdf
Conditional-Statement.pdf
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
CPU
CPUCPU
CPU
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
control statement
control statement control statement
control statement
 
controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docx
 
C tutorial
C tutorialC tutorial
C tutorial
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 

Mehr von vikram mahendra

Mehr von 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
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
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
 
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
 
Boolean logic
Boolean logicBoolean logic
Boolean logic
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
LIST IN PYTHON[SELECTION SORT]
LIST IN PYTHON[SELECTION SORT]LIST IN PYTHON[SELECTION SORT]
LIST IN PYTHON[SELECTION SORT]
 
DATA REPRESENTATION-NUMBER SYSTEM-PART-5
DATA REPRESENTATION-NUMBER SYSTEM-PART-5DATA REPRESENTATION-NUMBER SYSTEM-PART-5
DATA REPRESENTATION-NUMBER SYSTEM-PART-5
 
DATA REPRESENTATION-NUMBER SYSTEM
DATA REPRESENTATION-NUMBER SYSTEMDATA REPRESENTATION-NUMBER SYSTEM
DATA REPRESENTATION-NUMBER SYSTEM
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
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.
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

FLOWOFCONTROL-IF..ELSE PYTHON

  • 1. Python Flow Control Class: XI Computer Science-083 If..else conditions Part-2
  • 2. if .. else Statement The if ..else.. statement is used to test a specific condition. If the condition is true , a block of code or block of statements will be executed, otherwise false section statement will be executed Syntax: if condition or expression: -----Statements------- -----Statements------- else: -----Statements------- -----Statements------- This is True part of if condition This is False part of if condition
  • 3. Let us understand how the if..else work F the question is to check the user input age is more than equal to 18 or not, if yes than display “Valid to Vote” , otherwise display “Not valid to vote” age=int(input(“Enter the age:”)) if (age>=18): print(“Valid to vote”) print(“Valid to vote”) else: Enter the age: 20 Valid to vote If the condition is TRUE If the condition is False
  • 4. Let us understand how the if..else work Program to accept number from user and check that number is positive or negative. no=int(input(“Enter the no:”)) if (no>0): print(“It’s a positive value”) print(“It’s a negative value”) else: Enter the no: -9 It’s a negative value
  • 5. Let us understand how the if..else work Program to accept number from user and check that number is even or odd. no=int(input(“Enter the no:”)) if (no%2==0): print(“It’s a Even number”) print(“It’s a Odd number”) else: Enter the no: 5 It’s a Odd number Enter the no: 2 It’s a Even number
  • 6. Let us understand how the if..else work Program to accept number from user and check that number is divisible by 3 or 7 or not no=int(input(“Enter the no:”)) if (no%3==0 or no%7==0): print(“Number is divisible by 3 or 7”) print(“Number is not divisible by 3 or 7”) else: Enter the no: 15 Number is divisible by 3 or 7
  • 7. Let us understand how the if..else work Program to accept year from user and check that year is a leap year or not. Example : year is leap year if it is divisible by 4 or 400 or 100 yy=int(input(“Enter the year:”)) if (yy%4==0 or yy%400==0 or yy%100!=0): print(“It’s a leap year”) print(“Its not a leap year”) else: Enter the year:2005 A year is said to be leap year, if the year is exactly divisible by 4 but and not divisible by 100. Year is also a leap year if it is exactly divisible by 400.
  • 8. Let us understand how the if..else work Program to accept number and find maximum between two numbers a=int(input(“Enter the value a:”)) if (a>b): print(“A greater than B”) print(“B is greater than A”) else: Enter the value a: 5 Enter the value b: 2 A is greater than B b=int(input(“Enter the value b:”))