-3

When I run the below code, it always returns Number please no matter what I enter. Why does this happen?

number = input("please type number: ")
if type(number) != int:
    print('Number please')
else:
    print('number')
divibisan
  • 11,659
  • 11
  • 40
  • 58

1 Answers1

-1

Try this, this should work:

string = input()
if string.isalpha():
   print("It is a string. You are correct!")
elif string.isdigit():
   print("Please enter a string.")
else:
   print("Please enter a proper string.")

The .isalpha is used for checking if it's a string. The .isdigit is used for checking if it's a number.

Hope it helps :)

Mahir Islam
  • 1,941
  • 2
  • 12
  • 33