Ala carte multiplication
unknown
python
2 years ago
567 B
8
Indexable
def multiply_without_operator(x, y):
# Determine the sign of the result
if (x < 0) ^ (y < 0):
sign = -1
else:
sign = 1
# Take the absolute values of x and y
x = abs(x)
y = abs(y)
result = 0
for _ in range(y):
result += x
return result * sign
# Input numbers
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
# Calculate the product and print the result
product = multiply_without_operator(num1, num2)
print(f"The product of {num1} and {num2} is {product}")
Editor is loading...