From 11cf0c02dc1455ddd095ae21bf9f4c928ff1c643 Mon Sep 17 00:00:00 2001 From: Patricia <142254044+PatriciaOM@users.noreply.github.com> Date: Wed, 7 Aug 2024 20:27:01 +0200 Subject: [PATCH] Reto #14 mouredev --- .../python/PatriciaOM.py" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/PatriciaOM.py" diff --git "a/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/PatriciaOM.py" "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/PatriciaOM.py" new file mode 100644 index 0000000000..b6311c95eb --- /dev/null +++ "b/Retos/Reto #14 - OCTAL Y HEXADECIMAL [F\303\241cil]/python/PatriciaOM.py" @@ -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) \ No newline at end of file