I need help solving a power problem in an alternate way.
The purpose is to show the result of the potentiation and the number of characters (or numbers) that appear in the result. The code I'll put next I got put to work through some conversions from character to integer and vice versa.
base = input('Base: ')
expoente = input('Expoente: ')
potencia = int(base) ** int(expoente)
print('Potência: %d' %potencia)
digito = len(str(potencia))
print('Digitos: %d' %digito)
However, when I made a call not specifically to the math library, I did not succeed in solving the problem. The result of the potencia
variable is correct, but the result of the digito
variable appears erroneously.
The code that did not work is similar to the previous one, it only has the changes changes below compared to the above.
# potencia = int(base) ** int(expoente) (Colocado como comentário para visualização)
import math
potencia = math.pow(int(base),int(expoente))
I do not know if the result of the variable potência
is an integer after the call of the mathematical library, or a variable of character type, even so I am trying to carry out the conversion of the supposed whole number to character through the use of the function len()
.
How could you solve the problem according to the second code?