i have tuple a=("Orange", [10,20,30], (24,25,66))
when user inputs "O" it shows indexes right 0 0 good ,
but when i enter 10 nothing happens why? it must show 1 0
a=("Orange", [10,20,30], (24,25,66))
q=input()
for i in a:
if isinstance(i,str):
if q in i:
print(a.index(i),i.index(q))
elif isinstance(i,tuple) or isinstance(i,list):
if q in i:
print(a.index(i),i.index(int(q)))
I realized my mistake thank y guys
1 more question then what if a=("Orange", ["10",20,30], (24,25,66))
how can i find indexes of "10" as string
>Solution :
When you enter 10, what really happens is that q is assigned to "10", ie a string of two characters.
Your tuple a contains a list of numbers: [10, 20, 30], and all of the elements are integers and none of them are strings.
You could change the elif to go looking for and integer like this:
...
elif isinstance(i,tuple) or isinstance(i,list):
num = int(q)
if num in i:
print(a.index(i), i.index(num))