Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 105 - 2625 PortGPt V2.1
P. 105

    8                    Conditional Statements

                                                                     in Python

                         Let’s surf

                             Conditional Statements                          The if Statement
                             The if…else Statement                           Nested if Statement
                             The if…elif…else Ladder

                      Let’s PLug-in

                        State whether the following statements are true or false.
                        1.    A low-level language is a programming language that is machine
                          dependent.                                                                       __________
                        2.    Python provides two commonly used functions input() and print() for input
                           and output.                                                                     __________
                        3.   Variables are memory reference points where we store values which can be

                           accessed or changed later.                                                       __________
                        4.   Assignment operators are used to compare the value of the two operands
                           and returns True or False accordingly.                                           __________

                     There are situations  in life  where we must  make  decisions  based  on the  circumstances.  For
                     example, if it rains, we will stay at home, or else we will 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. Whether the outcome is true or false, we must decide which action to
                     take and which statement to execute. In this chapter, we will learn about conditional statements
                     in Python.

                            CONDITIONAL STATEMENTS

                     Conditional  statements,  also known as decision-making  or control flow  statements,  are used
                     in programming to execute different blocks of code based on certain conditions. The following
                     conditional statements are available in Python:

                       if statement                                          if...else statement
                       Nested if statement                                   if…elif…else ladder

                                                                                        Conditional Statements in Python  103

| 100 101 102 103 104 105 106 107 108 109 110 |