-
-
Save parzibyte/ac832e066492d6bb994f0b9a5fd5e362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Convertir número negativo a positivo en Python | |
https://parzibyte.me/blog | |
""" | |
numero_negativo = -100 | |
positivo = numero_negativo * -1 | |
print( | |
f"El número negativo es {numero_negativo} y convertido a positivo es {positivo}") | |
# Con la función "abs" de valor absoluto también es posible | |
numero_negativo = -100 | |
positivo = abs(numero_negativo) | |
print( | |
f"El número negativo es {numero_negativo} y convertido a positivo con abs es {positivo}") | |
# Otra prueba | |
numero_usuario = float(input("Ingresa un número: ")) | |
# Convertir solo si es negativo | |
if numero_usuario < 0: | |
numero_usuario *= -1 | |
print(f"El número que ingresaste es {numero_usuario} de manera positiva") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment