Page 26 - PlusGPT_V2.1_C8_Flipbook
P. 26

2                    Conditional Statements



                                                                   in Python











                      Let’s surf
                           Decision Making Statements                   Some More Programs






                   Let’s PLug-in                                                                   Computational Thinking


                     If a = 8, b = 2 and c = 20, then what will be the output of the following statements:
                     1.   print(a > b and b < c)    =    _________________
                     2.   print(a ** b + c)            =   _________________

                     3.   print(a, b, c)          =      _________________
                     4.   print(a > b or b > c)   =      _________________
                     5.   print(a // b – 2 + c)    =     _________________





                  There are situations in life when we need to decide based on a situation. For example, if it rains, I will
                  stay at home or else I shall visit the market. Similar situations arise in programming as well, where we
                  need to make some decisions and based on these decisions, execute a set of commands. We need to
                  determine which action is to be taken and which statement is to be executed, if the outcome is true or
                  false. In this chapter, we will learn about decision making statements of Python.


                         DECISION MAKING STATEMENTS


                  Decision making in Python is done by called conditional statements which decide the flow of program
                  execution. The following conditional statements are available in Python:
                  •   if statement

                  •   if...else statement

                  •   Nested if statement
                  •   if…elif…else ladder







                  24    Premium Edition-VIII
   21   22   23   24   25   26   27   28   29   30   31