im trying to get this
rawstr = input('enter a number: ')
try:
ival = abs(rawstr)
except:
ival = 'boob'
if ival.isnumeric():
print('nice work')
else:
print('not a number')
to recognize negative numbers, but i cant figure out why it always returns 'is not a number' no matter what the input is
the original purpose of this was a learning excercise for try/except functions but i wanted it to recognise negative numbers as well, instead of returning 'is not a number' for anything less than 0
rawstr = input('enter a number: ')
try:
ival = int(rawstr)
except:
ival = -1
if ival > 0:
print('nice work')
else:
print('not a number')
^ this was the original code that i wanted to read negative numbers