Page 148 - C_GPT _V4 _class_7
P. 148

Program 6: To check if the given number is lucky or not, if the given number is greater than zero and
              is even, then print ‘Lucky number’ else print ‘Not a lucky number’


                   Program6.py
                File  Edit  Format   Run   Options   Window    Help

                #Program to check lucky number
                number = int(input('Enter a number: '))
                if(number > 0):
                    if(number % 2 == 0):
                        print('Lucky number')
                    else:
                        print('Not a lucky number')
                else:
                    print('Try again....')




              On running the above program, we get the following output:


                   Output

                Enter a number: 21
                Not a lucky number


                Enter a number: 12
                Lucky number






                        Interdisciplinary Learning                                                    Lab Activity


                  Write the logic in Word document to check if the input number is positive or negative. Write the program
                  in Python for the logic created.




              THE IF…ELIF…ELSE LADDER


              The if…elif…else ladder is another type of if statement. It helps us to test multiple conditions and
              follows a top-down approach. In this, as soon as the condition of the if evaluates to true, the indented
              block associated with that ‘if’ is executed, and the rest of the ladder is avoided.

              If none of the conditions evaluates to true, then the final else statement gets executed.
              The syntax of if...elif...else ladder is shown below:

              Syntax:

              if (Test Expressions_1):



                        CodeGPT (Ver. 4.0)-VII
                146
   143   144   145   146   147   148   149   150   151   152   153