Page 422 - Ai_417_V3.0_C9_Flipbook
P. 422

Ans.  In  sequential  flow,  the  statements  are  placed  one  after  the  other  and  the  flow  of  execution  occurs  starting  from
                    line 1, line 2 and so on with a top to down approach. It is the default flow followed in any programming language. For
                    example, the steps for calculating the percentage of any student
                    1.  Input marks of English, Hindi, and Math
                    2.  Total the marks
                    3.  Calculate the percentage
                    4.  Display the percentage
                  2.  Explain the important symbols of flowchart.

                Ans.     Symbol              Description
                         Oval                Used to start and end a flowchart.
                         Parallelogram       Used for input and output operation.

                         Rectangle           Used for assignment, mathematical operations,
                                             processing

                         Diamond             Used for decision-making in case of branching
                                             or looping.
                         Arrow               Used  to  show  the  direction  of  the  flow  of
                                             information.
                  3.  Explain the use of print( ) function with all its parameters.
                Ans.  The print() function is used to print an output on the screen. It converts the expressions into a string before writing to
                    the screen. Syntax to use the print( ) function is:
                        print(object(s), sep = separator, end = end)

                     Where,
                    •  object can be one or more separated by comma and it can be a variable, literal, expression. An object will be
                      converted to string before printed.
                    •  sep is used as a separator if there are more than one objects.
                    •  end specifies what to print at the end. Default is newline '\n'.
                  4.  Give two different ways of writing statements in Python.
                Ans.  •   Simple statements: By default, the end of a statement is done by pressing an Enter key. Each statement is
                      written on a new line.
                       a=5 is a simple statement where variable-a is created with value 5.
                       c=a + b

                    •  Multiline Statements:  We  can  make  a  statement  that  extends  over  multiple  lines  by  using  line  continuation
                      character (\) as shown below:

                       a = 4 + 5 +\
                       6 + 7 +\
                       8 + 9
                    •  The main advantage of using multiline is when we need to do long calculations and cannot fit these statements into
                      one line.
                  5.  Explain if…else statement with example.
                Ans.  When the condition is 'True' then the statements indented just below the if statement will be executed and if the
                    condition is 'False' then the statements indented just below the else statement will be executed. Syntax is:
                      if (condition):

                    420     Touchpad Artificial Intelligence (Ver. 3.0)-IX
   417   418   419   420   421   422   423   424   425   426   427