hi im having this problem this is my code rn but it wont do anything or just say its a int or a str
b=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
c=['&','!','@','#','$','%']
a = input("Enter here :")
if type(a) ==int:
print("number")
if a==b:
print("word")
if a ==c:
print("symbol")
I tried putting a int or a str behind a input thing but that didn't solve the prob i wanna write a code as clean as possible and not with list cuz they are long and hard to make.
CodePudding user response:
The question is worded a little strangely but i'll give it a go. B is a list, so saying a==b will not be true if it is a word. you may be looking to see if the charater passed in (a) is IN list b. for that you will want to do if a in b
. Also i believe all of the inputs a will come in as a string, so the first line if type(a) == int
will never be true.
I would most likely use the is numeric function on the string input
if a.isnumeric():
you have some more work to do, I hope this was helpful and wish you luck
CodePudding user response:
There are couple things you need to know. First of all, output of input function is always a string. So even though you enter a number like 523, python will see it as a string: "523".
You can use isnumeric to check if it can be converted into numbers like:
if(a.isnumeric()):print("number")
Secondly, if b is an array and you check equality of an array and a string which is a. In this case result will always be False. So you should check like this
if(a in b):
...
and it's also same for c