0
n = input("enter a number:")
if (float(n))> 0:
    print('Positive') 
elif (float(n))< 0:
    print('Negative')
elif n== '0': 
    print('Zero')
else:
    print('not a number') 

Everything works as intended except for when i input something like 'erght'.

Adam
  • 23
  • 4
  • Please update your question with the full error traceback. – quamrana Dec 09 '20 at 21:26
  • 1
    Does this answer your question? [Checking if a string can be converted to float in Python](https://stackoverflow.com/questions/736043/checking-if-a-string-can-be-converted-to-float-in-python) – Axiumin_ Dec 09 '20 at 21:27

1 Answers1

4

If you enter a string, then float(n) will throw and error. You should use a try-except block.

n = input("enter a number:")
try:
    n = float(n)
    if n>0:
        print('Positive') 
    elif n<0:
        print('Negative')
    else: 
        print('Zero')
except:
    print('not a number') 
bkakilli
  • 498
  • 6
  • 12