Page 334 - AI Ver 1.0 Class 10
P. 334
factorial = 1
if n < 0:
print("Factorial does not exist for negative numbers")
elif n == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,n + 1):
factorial = factorial*i
print("The factorial of ",n," is",factorial)
Output:
Enter a number: 7
The factorial of 7 is 5040
4. 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. Program:
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")
Output:
Input the sides of the triangle:
A: 10
B: 10
C: 10
Equilateral triangle
5. Write a program to input two numbers and display the LCM of the two numbers.
Ans. Program:
def calculate_lcm(x,y):
if x > y:
greater = x
332 Touchpad Artificial Intelligence-X

