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')
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')
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 :)