Page 1 :
Unit I: Computational Thinking and Programming - 1, , Chapter- 11 Conditional Statements in Python, , “Keep your thoughts positive and flow with life.”, , Sa. BK te), , , , , , , , , , , , , , , , , , , , , , , , , , 1 Introduction: Flow of Control, , 2 Types of Control Structure, , 3 1. Sequence Statement:, , 4 2. Selection Programming Control Structure, , 5 A) if statement, , 6 B) if — else statement, , 7 C) if — elif — else or Ladder if — else statement, 8 D) Nested _ if — else Statement, , , , , , , , , , Page 1 of 13
Page 2 :
Unit I: Computational Thinking and Programming - 1, , Chapter- 11 Conditional Statements in Python, , Any computing problem can be solved by executing a series of actions in, a specified order., , For example, you want the program to take some decisions and do, different things depending on different situations, such as printing, , ‘Qualified’ or ‘Not Qualified’ depending on the Grade achieved in exams., , Specifying the order in which statements execute in a computer program, is called program control., , Control structures are used to alter the flow of execution of, the program., , AUER ieadtigy Sequence, four types of selection, , and two types of repetition., , Control Structure, , while loop, , , , if - elif- else, , ES revel, if - else, , , , Page 2 of 13
Page 3 :
Unit I: Computational Thinking and Programming - 1, , Chapter- 11 Conditional Statements in Python, , > The sequence structure is built into, , , , Sequential, python. enue, , > Normally the statements that make up a, Statement 2, , python program are executed in the, order that they are written is known as ed, , sequence statement., , End 3, , Example:, , a = int(input(“Enter Number 1: ”)), b = int(input(“Enter Number 2 : ”)), , = 0, r =a + b # addition of two numbers - Line 1, , print ("The sum is (Line -1)", r), , r =a -— b # Subtraction of two numbers - Line 2, print ("The Subtraction is (Line -2) ", r), , r =a * b # Multiplication of two numbers - Line 3, print ("The Multiplication is (Line -3) ", r), r =a / b # Division of two numbers - Line 4, , print ("The Division is (Line -4)", r), , In the above given example statements are executed in sequence i.e. in, same order that they are written. The output is:, , Enter Number 1 : 20, , Enter Number 2 : 10, , The sum is (Line -1) 30, , The Subtraction is (Line -2) 10, , The Multiplication is (Line -3) 200, The Division op is (Line -4) 2.0, , Page 3 of 13
Page 4 :
Unit I: Computational Thinking and Programming - 1, , Chapter- 11 Conditional Statements in Python, , In Python, the selection statements are also known as decision making, , statements or branching statements., , In the selection statement the execution of statement will depend upon, the test condition. If the test condition is true then it will execute Action 1, otherwise Action 2., , UA oo atc, , , , 1. if statement, 2. if — else statement, 3. if — elif — else or Ladder if — else statement, , 4. Nested if — else statement, , , , PAE, , >The if selection structure either Start, performs (selects) an action if a, , condition (predicate) is true or skips, , the action if the condition is false. — cS, , >The if selection structure can TRUE, , If conditional, , contain several statements in the Statement, , , , , , body of an if statement, and all, , Next Statement, , these statements must be indented., , Page 4 of 13
Page 5 :
Unit I: Computational Thinking and Programming - 1, , Chapter- 11 ditional Statements in Python, Syntax for if State, , If test_condition:, , , , , , , Statement1, , _otatements, , > It must contain valid condition which evaluates to either True or False, > Condition must followed by Colon (:) , it is mandatory, > Statement inside if must be at same indentation level., , Example 1: Write a python code to input total marks in 5 subjects. Find, the percentage and print “Grade A “and “Excellent” in two separate line, if the percentage is greater than 90., , Code:, Tmarks = float(input( "Enter Total Marks of 5 subjects " )), , perc = Tmarks/5, , print ( "Your Percentage is: ", perc), , Enter Total Marks of 5 subjects 359, Your Percentage is: 71.8, >>>, , if perc>9® :, print( "Grade A" ), , , , , , RESTART: D:/XI, , , , , , print( "Excellent" ) Enter Total Marks of 5 subjects 456, Your Percentage is: 91.2, Grade A, Excellent, , In the above example, If the value of percentage (perc) is greater than to, 90, the line of code in the block executes. Otherwise, python code skips, the entire block. As shown in the above given output., , Page 5 of 13