Page 310 - Ai_C10_Flipbook
P. 310

12.   Write a Python code to input the lengths of the three sides of a triangle and display whether a triangle can be
                    formed with the inputs or not. If a triangle can be formed then display whether the triangle will be scalene,
                    isosceles or equilateral triangle.

               Ans.  [1]:  print("Input the sides of the triangle: ")
                           A = int(input("A: "))
                           B = int(input("B: "))
                           C = int(input("C: "))
                           if A == B == C:
                               print("Equilateral triangle")
                           elif A==B or B==C or A==C:
                               print("isosceles triangle")
                           else:
                               print("Scalene triangle")

                           Input the sides of the triangle:
                           A: 10
                           B: 10
                           C: 10
                           Equilateral triangle

                13.  Write a program to input two numbers and display the LCM of the two numbers.

               Ans.  [1]:  def calculate_lcm(x, y):
                               if x > y:
                                   greater = x
                               else:
                                   greater = y
                               while(True):
                                   if((greater % x == 0) and (greater % y == 0)):
                                       lcm = greater
                                       break
                                   greater += 1
                               return lcm  # Corrected the indentation here
                           num1 = int(input("Enter first number: "))
                           num2 = int(input("Enter second number: "))
                           print("The L.C.M. of", num1,"and", num2,"is", calculate_lcm(num1, num2))
                           Enter first number: 5
                           Enter second number: 6
                           The L.C.M. of 5 and 6 is 30

                14.  Write a program to input a number and display whether it is a palindrome or not.

               Ans.  [1]:  num=int(input("Enter a number:"))
                           temp=num
                           rev=0
                           while(num>0):
                               dig=num%10
                               rev=rev*10+dig
                               num=num//10
                           if(temp==rev):
                               print("The number is a palindrome!")
                           else:
                               print("The number is not a palindrome!")

                           Enter a number:1002001
                           The number is a palindrome!



                    308     Artificial Intelligence Play (Ver 1.0)-X
   305   306   307   308   309   310   311   312   313   314   315