Page 246 - Ai_V1.0_Class9
P. 246

Source Code:

              Amount=float(input("Enter Billing Amount: Rs. "))
              Age=int(input("Enter Age: "))
              if Amount > 10000:
                  if Age >= 60:
                      print("Final billing amount after 15 % discount: Rs. ",Amount-(0.15*Amount))
                  else:

                      print("Final billing amount after 10 % discount: Rs. ",Amount-(0.10*Amount))
              else:
                  print("Sorry! No Discount")
              Output:

              Enter Billing Amount: Rs. 15000
              Enter Age: 61

              Final billing amount after 15 % discount: Rs. 12750.0


                            Brainy Fact


                   True means non-zero number or non-empty object and False means None or zero number or empty
                   object or none.





                       Iterative  Statements

              In Python, the process of repeating a set of instructions based on a condition is called loop or iteration. There
              are two types of loops in Python—for loop and while loop. Let us learn about them in detail.


              The for Loop
              The for loop is used to repeat a set of instructions for a fixed number of times. This means the number of
              iterations are known/definite before we start the execution of the loop. Therefore, the for loop is also known
              as definite loop. Indentation of statements is must to specify the block of statements to be repeated using the
              for loop. There are commonly two different ways of using the 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
                 Where,
                    ✶ for is a keyword.
                    ✶ counter variable is any identifier that keeps a count of the loop.

                    ✶ sequence is any values like integer, string, list, etc.
                    ✶ Statements are always indented can be single or a block.





                    244     Artificial Intelligence Play (Ver 1.0)-IX
   241   242   243   244   245   246   247   248   249   250   251