This question brings to light the very definition of multiplicação
.
What is multiplication?
Multiplication is nothing more than soma
of parcelas iguais
.
Example 1: How much 2 x 4?
(2 * 4) == 4 + 4 == 8
This means that 2 x 4
is the summing up of 2
plots of 4
.
Example 2: how much is 3 x 9?
(3 * 9) == 9 + 9 + 9 == 27
This means that 3 x 9
is the summing up of 3
plots of 9
.
If we accept the condition that multiplicação
in the set of real numbers is comutativa
, we can say that:
(2 * 4) == (4 * 2) == 2 + 2 + 2 + 2 == 8
That is to say, 4 x 2
is the soma
of 4
plots of 2
and...
(3 * 9) == (9 * 3) == 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 == 27
That is to say, 9 x 3
is the soma
of 9
plots of 3
.
Now, with this explanation it becomes much easier to implement a laço de repetição
to calculate the product between two fatores
without using the operador
of multiplicação
.
If you want to use the loop for
to resolve this issue, you can use the following algorithm...
f1 = int(input('Digite o primeiro fator: '))
f2 = int(input('Digite o segundo fator: '))
soma = 0
for c in range(f1, f2 + f1):
soma += f1
print(f'\033[32mO produto é: {soma}')
Note the functioning of the algorithm in repl it.
Note that f1
is the first factor and f2
is the second factor.
Very good your code, but I could not understand it. Could you explain to me what is happening in the code? Because I wanted to make the code myself, you know? Understand the idea and create my own :/
– Paula Jaqueline Silva