Advertisement
cardel

Grupo P75 Ejemplo

May 11th, 2021
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. '''
  2. Autor: Carlos A Delgado
  3. Fecha: 11 de Mayo de 2021
  4. algoritmo pereira_es_potencia
  5. variables
  6.     x,y,b int
  7. inicio
  8.     obtener x,y
  9.     SI y == 0 O y==1 O y < 0
  10.         retornar Falso
  11.     SINO:
  12.         b = log2(y)//log2(x)
  13.         SI x**b == y
  14.             retornar True
  15.         SINO
  16.             retornar Falso
  17. '''
  18. import math as md
  19.  
  20. def pereira_es_potencia(x:int, y:int)->bool:
  21.     '''
  22.    x: int Es el valor de x al cual vamos a elevar
  23.    y: int Es el valor resultante de elevar x al número misterioso
  24.    Retona: bool, el cual indica si ese número entero misterioso existe
  25.    '''
  26.     if y == 0 or y == 1 or y < 0:
  27.         return False
  28.     else:
  29.         b = md.log2(y)//md.log2(x)
  30.         if x**b == y:
  31.             return True
  32.         else:
  33.             return False
  34.  
  35. print(pereira_es_potencia(2,8)) #True
  36. print(pereira_es_potencia(3,45)) #False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement