Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 5, 2021 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ac832e066492d6bb994f0b9a5fd5e362 to your computer and use it in GitHub Desktop.
Save parzibyte/ac832e066492d6bb994f0b9a5fd5e362 to your computer and use it in GitHub Desktop.
"""
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