Skip to content

Commit

Permalink
Reto mouredev#14 mouredev
Browse files Browse the repository at this point in the history
  • Loading branch information
PatriciaOM authored Aug 7, 2024
1 parent 48a3120 commit 11cf0c0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Retos/Reto #14 - OCTAL Y HEXADECIMAL [Fácil]/python/PatriciaOM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Crea una función que reciba un número decimal y lo trasforme a Octal
y Hexadecimal.
No está permitido usar funciones propias del lenguaje de programación que
realicen esas operaciones directamente.
"""

def decimal_octal_hexadecimal(number):
user_number = number
octal = list()
hexadecimal = list()
#Octal
while number > 0:
octal.append(str(number % 8))
number = number // 8 #cambiamos al nuevo valor
octal.reverse() #le damos la vuelta para conseguir el orden correcto
octal_str = ''.join(octal) #lo convertimos en string para imprimir
#Hexadecimal
while user_number > 0:
module = user_number % 16
if module == 10:
hexadecimal.append("A")
elif module == 11:
hexadecimal.append("B")
elif module == 12:
hexadecimal.append("C")
elif module == 13:
hexadecimal.append("D")
elif module == 14:
hexadecimal.append("E")
elif module == 15:
hexadecimal.append("F")
else:
hexadecimal.append(str(module))
user_number = user_number // 16
hexadecimal.reverse()
hexadecimal_str = ''.join(hexadecimal)
print(octal_str)
print(hexadecimal_str)

decimal_octal_hexadecimal(4634534)

0 comments on commit 11cf0c0

Please sign in to comment.