Page 284 - Ai_C10_Flipbook
P. 284

[2]:   Year=int(input("Enter year: "))
                      if Year%4==0 or Year%100==0 and Year%400==0:
                          print("Leap Year")
                      else:
                          print("Not a Leap Year")

                      Enter year:  2025
                      Not a Leap Year

               [3]:   Gender = str(input("Enter Gender (M/F): "))
                      Age = int(input("Enter Age: "))

                      if Gender == "M" and Age >= 21:
                          print("Eligible for Marriage")
                      elif Gender == "F" and Age >= 18:
                          print("Eligible for Marriage")
                      else:
                          print("Not Eligible for Marriage")

                      Enter Gender (M/F):  F
                      Enter Age:  25
                      Eligible for Marriage

               [4]:   N1 = int(input("Enter the first number: "))
                      N2 = int(input("Enter the second number: "))
                      N3 = int(input("Enter the third number: "))

                      if N1 >= N2 and N1 >= N3:
                          print("The largest number is: ", N1)
                      elif N2 >= N1 and N2 >= N3:
                          print("The largest number is: ", N2)
                      else:
                          print("The largest number is: ", N3)

                      Enter the first number:  85
                      Enter the second number:  15
                      Enter the third number:  102
                      The largest number is:  102
              Looping Statements

              The process of repetition of a set of instructions based on a criterion is called a loop. There are two types of
              looping statements in Python, let us study about them in detail.

              The for Loop
              The for loop is used to repeat a set of instructions for a fixed number of times. It means when the number of
              iterations is known/definite before we start with the execution of a loop. It is therefore also known as a definite
              loop. Indentation of statements is must to specify the block of statements to be repeated using for loop. Let us
              understand the flow of for loop with the help of a flowchart. There are commonly two different ways of using
              for loop.

              Using Sequence
              In this type of for loop, a sequence of values is used over which the loop iterate. The syntax to use the for loop
              with a sequence is:
                   for <counter variable> in <sequence>:
                          Statements

                    282     Artificial Intelligence Play (Ver 1.0)-X
   279   280   281   282   283   284   285   286   287   288   289