Page 494 - ComputerScience_Class_11
P. 494

Start




                                                  false       if (condition)?    true





                                        Statements 2                              Statements 1








                                                                 Stop

              Program 3: Write a program to enter three angles of a triangle and check if a triangle is possible or not. A triangle is
              possible if the sum of its angles is equal to 180.

                   Program 3.py

               File  Edit  Format    Run   Options   Window    Help

                a=float(input('Enter the first angle: '))
                b=float(input('Enter the second angle: '))

                c=float(input('Enter the third angle: '))
                if a+b+c==180:

                    print('Triangle is possible')
                else:

                    print('Triangle not possible')





                   Output

                Enter the first angle: 45
                Enter the second angle: 90
                Enter the third angle: 45
                Triangle is possible




              The elif Statement
              The elif statement in Python stands for "else if". It is used to check multiple conditions in a program after the initial if
              statement. If the first condition is not true, the program checks the condition specified by the elif statement. If that
              condition is true, the corresponding block of code is executed.








                  492  Touchpad Computer Science (Ver. 3.0)-XI
   489   490   491   492   493   494   495   496   497   498   499