Logic Building
# Take three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
# Check GP (avoid division by zero)
if a != 0 and b != 0:
if (b / a) == (c / b):
print("Geometric progression")
else:
print("Not a geometric progression")
else:
print("Cannot form GP with zero")Output
Enter first number: 2 Enter second number: 4 Enter third number: 8 Geometric progression Enter first number: 2 Enter second number: 5 Enter third number: 8 Not a geometric progression
In GP, ratio between consecutive terms is constant.
Key Concepts:
- Check if (b/a) == (c/b)
- Handle division by zero
- Common ratio must be same