1

I'm writing a program and it asks the user to input a number, I need to make sure that that number is and actual number not a string. That number can be positive or negative. I've tried using .isnumerical() and .isdigit() but they won't except negative numbers.

lowest_num = input("What would you like the lowest possible number to be?")
while lowest_num.isdigit() is not True:
    lowest_num = (input("Please only enter a number : ")).lower()

Thanks for the help in advance

MarianD
  • 13,096
  • 12
  • 42
  • 54
  • Possible duplicate of [How do I check if input is a number in Python?](https://stackoverflow.com/questions/20095244/how-do-i-check-if-input-is-a-number-in-python) – APorter1031 Jan 07 '18 at 01:26

2 Answers2

0

lowest_num = int(input("What would you like the lowest possible number to be?")) should do it

Alright, try this:

number_not_entered = True
num = 0 
while number_not_entered:
  try: 
    num = int(input("enter num"))
    number_not_entered = False
  except ValueError:
    print("please try again")

Note that catching all exceptions is generally a bad practice.

information_interchange
  • 2,538
  • 6
  • 31
  • 49
0

Use isnan() function from numpy library. First import numpy and then use numpy.isnan(a number)

information_interchange
  • 2,538
  • 6
  • 31
  • 49
Ali E
  • 1
  • 1