Page 209 - AI Ver 1.0 Class 10
P. 209

• It should not be a Python keyword.
                          • They are case sensitive. Uppercase and lowercase letters are different.

                 B.  Long answer type questions:

                    1.  Give three advantages of using Python for AI.
                   Ans.  Advantages of using Python for AI are:
                          • It is easy to read, write, learn and maintain: It has simple English-like statements which are easy to learn and use.
                         Anybody can easily get used to its syntax and can expertise in it.
                          • Large standard library: Python has plenty of built-in modules and packages for dealing with plenty of different
                         kinds of problems especially related to AI. These important libraries make it popular specially in AI based
                         programs where we need to focus more on its use and not in its core design.
                          • Interactive Mode: The interactive mode in Python gives flexibility of testing and debugging the code snippets before
                         implementing in actual AI model.
                    2.  Give the Python code for the given questions.

                       Find out whether a given number is prime or not.
                   Ans. num=int(input("enter a number "))
                                  if num > 1:
                                  for i in range(2, num//2):
                                       if num % i==0:
                                             print(num, "is not a prime number")
                                             break
                                  else:
                                             print(num, "is a prime number")
                                             else:
                                             print(num, "is not a prime number")
                    3.  Write a Python program to input price and quantity. Calculate the amount and if amount >10,000 give 20% discount
                       otherwise give 10% discount.

                   Ans.  Price=float(input("Price:"))
                       Qty=int(input("Qty:"))
                       Amt=Price*Qty
                       if Amt>10000:

                        Discount=20
                       else:
                        Discount=10
                       Amt=Amt-Amt*Discount/100

                       print("Discounted Amt:",Amt)
                    4.  Write a Python code to accept shape and accept Length, Breadth or Side or Radius depending on shape, calculate
                       perimeter and area.
                   Ans.  Shape=input(“Enter shape :”)
                       if Shape=="S":

                        S=int(input("Side:"))
                       A=S*S;P=4*S
                       elif Shape=="R":
                                                                                           Advance Python   207
   204   205   206   207   208   209   210   211   212   213   214