0% found this document useful (0 votes)
6 views

Day5_PythonDecesion_Making

Uploaded by

jayantascribe
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Day5_PythonDecesion_Making

Uploaded by

jayantascribe
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

NATIONAL

[Unit INSTITUTE
1: Introduction OF ELECTRONICS
to Web Design] AND
Course: INFORMATION
NIELIT TECHNOLOGY
‘O’ Level (IT)
Sumit Complex, A-1/9, Vibhuti Khand,
Module: Gomti
M2-R5: Nagar,
Web Lucknow,
Designing & Publishing
1

File and Printer sharing in Windows NT


Environment

Basic Python
Day5
[UnitCourse
1: Introduction to Web Design]
: Basic Python
Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
2 Index
 Decision Making in Python
 Indentation in Python
 The if statement
 The if…..elif….else statement
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
3 Decision Making in Python
In python, decision making is performed by the following statements.
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
4
 IF FLOW CHART.
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
5 Indentation in Python
 In python, decision making is performed by the following statements.
 For the ease of programming and to achieve simplicity, python doesn't allow the use of
parentheses for the block level code.
 Indentation is used to declare a block. If two statements are at the same indentation level, then
they are the part of the same block.
 Four spaces are given to indent the statements which are a typical amount of indentation in
python.
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
6 The if statement
 The if statement is used to test a particular condition and if the condition is true, it executes a
block of code known as if-block.
 If it amounts to False, then the block is skipped and control transfers to the statements after
the block.
 The syntax of the if-statement is given below.
 if condition:
 statement
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
7
 The if statement is used to test a particular condition and if the condition is true, it executes a block
of code known as if-block.
 If it amounts to False, then the block is skipped and control transfers to the statements after the block.
 The syntax of the if-statement is given below.
 if condition:
 statement
 Example
 num = int (input("enter the number:"))
 if(num%2 == 0):
 print("Number is even")
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
8
 Example
 num = int (input("enter the number:"))
 if(num%2 == 0):
 print("Number is even")

 Note:

 Remember to indent the statements in a block equally.

 This is because we don’t use curly braces to delimit blocks.

 Use a colon (:) after the condition. It is mandatory.


[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
9
 The if-else statement provides an else block which is executed when the given condition is false.
 If the condition is true, then the if-block is executed. Otherwise, the else-block is executed.
 Syntax: if condition:
 statement if condition is true
 else:
 statement if condition is false
 Example
 num = int (input("enter the number:"))
 if(num%2 == 0):
 print("Number is even")
 else:
 print(“Number is odd”)
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
10 The if…..elif….else statement
 The elif is short for else if. It allows us to check for multiple conditions.
 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, 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.
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
11
 Syntax: if condition 1:
 # block of statements
 elif condition 2:
 # block of statements
 elif condition 3:
 # block of statements
 else:
 # block of statements
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
12 Example
 Python Program to obtain the grade. The grades are decided on following condition:

A) If marks are greater than 85, the grade is A.


B) If marks are greater than 60 and less than or equal to 85, the grade is B.
C) If marks are greater than 50 and less than or equal to 60, the grade is C.
D) If marks are greater than 40 and less than or equal to 50, the grade is D.
E) Otherwise, Fail
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
13 Solution
 marks = int(input("Enter the marks: "))
 if(marks > 85 and marks <= 100):
 print("Congrats ! you scored grade A")
 elif(marks > 60 and marks <= 85):
 print("You scored grade B ")
 elif(marks > 50 and marks <= 60):
 print("You scored grade C ")
 elif (marks > 40 and marks <= 50):
 print("You scored grade D ")
 else:
 print("Sorry you are fail")
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
14 Assignment:
 WAP to input the number and check it is even or odd.
 WAP to check a number is positive or negative.
 WAP to check greatest among two numbers.
 WAP to check a year leap year or not.
 WAP to check greatest among three numbers.
 WAP to check a three digit number is palindrome or not.
 WAP to input the cost price and selling price of an item and check for profit or loss. Also
calculate it.
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
15 References
 https://www.javatpoint.com/python-tutorial
 https://www.w3schools.com/python/
 https://www.tutorialspoint.com/python/index.htm
 https://www.programiz.com/python-programming
 https://www.geeksforgeeks.org/
[UnitCourse
1: Introduction to Web Design]
: Basic Python Course: NIELIT ‘O’ Level (IT)
Day5 : Python Decision Making Module: M2-R5: Web Designing & Publishing
16

Thank You

You might also like