0
t= int(input())
ar=[]
chk=0
x=0
y=0
while(t>0)
    i=int(input())
    for l in range(i):
        ar= int(input())
    for l in range(i-1):
        for m in range(l+1,i):
            x=ar[l]
            y=ar[m]
            k=x*y
            if k in ar:
                continue
            else:
                chk=chk+1
    print(True)
    if chk>0:
        print(False)
    t-=1

Error:

x=ar[l]

TypeError: 'int' object is not subscriptable

in this program i am tryng to print true if all the all the pairs in the array follow the relation x= a*b where x is any element in array and a abd b are the elements of the pair.

3
  • ar is an integer: ar = int(input()). You can't subscript an integer. Commented Apr 20, 2017 at 19:38
  • In the loop above, put ar[l] = int(input()) instead of ar= int(input()) Commented Apr 20, 2017 at 19:40
  • I'm voting to close because this is just a typo. Commented Apr 20, 2017 at 19:41

2 Answers 2

1

What you intend to do is append the input to the ar. Use

ar.append(int(input())

instead of

ar = int(input())

which changes ar type from list to int, and it's no longer possible to access it using indices.

Sign up to request clarification or add additional context in comments.

Comments

0

You are using ar wrong. First you use ar like a list, and then like an int.

ar=[]               # You are using ar like a list
ar= int(input())    # Now, you are using ar like an int

You have to append the value:

ar.append(int(input()))

Now you are making a good list!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.