Page 495 - AI Ver 3.0 class 10_Flipbook
P. 495
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!
Python Practical Questions 493

