Page 336 - AI Ver 1.0 Class 10
P. 336

else:
                        print(num, "is a prime number")
                   else:
                        print(num, "is not a prime number")
                    Output:
                    Enter a number: 12
                    12 is not a prime number

                8.  Write a program to input two numbers and swap both the numbers without using the third number.
               Ans.  Program:

                    x = int(input("Enter the value of x: "))
                   y = int(input("Enter the value of y: "))
                   print("Numbers before swapping: %d   %d\n" %(x,y))
                   x = x + y

                   y = x - y
                   x = x - y
                   print("Numbers after swapping: %d   %d\n"%(x,y))
                    Output:
                    Enter the value of x: 22
                    Enter the value of y: 14

                    Numbers before swapping: 22 14
                    Numbers after swapping: 14   22

                9.  Using Numpy Package:
                      • Create a 4×2 array with random integer.

                      • Create 3×3 array with all zeros.
               Ans.  Program:

                    import numpy as np
                   r = np.random.rand(4,2)
                   print(r)
                   import numpy as np

                   a = np.zeros((3,3))
                   print(a)
                    Output:
                    [[0.01770743 0.50604842]
                     [0.40198197 0.974359    ]
                     [0.35439403 0.6841792  ]

                     [0.99028845 0.57243665]]
                    [[0. 0. 0.]





                        334   Touchpad Artificial Intelligence-X
   331   332   333   334   335   336   337   338   339   340   341