-4

I want to write a program which does: If the input number is positive, just print it out; If the input number is negative, print the abs number; if not a number, print "Error"

I don't know how to do the last step.

1 Answers1

0

This should work as you said:

num = input( 'need a number:' )
try :
    num = int(num)
    print( abs(num) )
except ValueError :
    print( 'not a number' )
lenik
  • 23,228
  • 4
  • 34
  • 43
  • You need to move `print( abs(num) )` into the `try` block, otherwise you'll get a second error trying to call `abs` on a string. – kaya3 Nov 12 '19 at 02:30