Answers for "python positive integer"

12

python input integer

# To prompt the user to input an integer we do the following:
valid = False

while not valid: #loop until the user enters a valid int
    try:
        x = int(input('Enter an integer: '))
        valid = True #if this point is reached, x is a valid int
    except ValueError:
        print('Please only input digits')
Posted by: Guest on April-03-2020
2

python convert any number in positive

a = abs(-1)
return a

#returns 1
Posted by: Guest on June-16-2020
-2

how to make a negative number positive in python

x = abs(x)
Posted by: Guest on August-26-2021

Code answers related to "python positive integer"

Python Answers by Framework

Browse Popular Code Answers by Language