SlideShare una empresa de Scribd logo
1 de 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:”))

Más contenido relacionado

La actualidad más candente

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

La actualidad más candente (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
 

Similar a 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
 

Similar a 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
 

Más de vikram mahendra

Más de 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
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

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
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
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.
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
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Ữ Â...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

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:”))