18.2k views
0 votes
In ancient times, Egyptians did not use multiplication tables. Instead, they transformed any calculation into multiplication by two, and additions. The principle of Egyptian multiplication is the following: (x∗y)=2∗(x∗(y/2)) if y is even, and (x∗y)=x+(x∗(y−1)) if y is odd. For instance, (7∗10)=(2∗(7∗5))=(2∗(7+(7∗4)))=(2∗(7+(2∗(7∗2)))). Write a recursive Python function that, given two strictly positive integers x and y (the arguments of the function), returns the result of x∗y obtained using the Egyptian method. Of course, directly multiplying x by y is allowed in your code if and only if x≤2 or y≤2. You can use division and the % operator. Test your function with two distinct products.

1 Answer

1 vote

Final answer:

The Egyptian method of multiplication in ancient times involved transforming calculations into multiplication by two and additions. A recursive Python function can be used to implement this method.

Step-by-step explanation:

The Egyptian method of multiplication in ancient times involved transforming calculations into multiplication by two and additions. The recursive Python function for this method would be:

def egyptian_multiplication(x, y):
if y == 1:
return x
elif y % 2 == 0:
return 2 * egyptian_multiplication(x, y//2)
else:
return x + egyptian_multiplication(x, y-1)

x = int(input('Enter the first number: '))
y = int(input('Enter the second number: '))
result = egyptian_multiplication(x, y)
print('Result:', result)

By following this function, you can obtain the result of x*y using the Egyptian method. Make sure to test it with two distinct products.

User Mcryan
by
8.0k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.

9.4m questions

12.2m answers

Categories