jeudi 19 août 2021

Python if statement not computing value

First baby steps into Python and I'm stuck. I want to print the absolute value of an integer that is input by the user. If the integer that is input is a negative value, I want it to return a positive value. I'm converting the string to an integer fine, I'm storing the input 'number' fine, but if I input a negative number it's not doing the eval of the if statement and converting to a positive number by * -1 as you see below. I'm at a loss, should I be defining another variable somewhere here?

number = int(input('Please enter a number: '))

if number <= 0:
    number = number * -1

Aucun commentaire:

Enregistrer un commentaire