0
import math
import location
if __name__ == "__main__" :
    locationlist = []
    while True :
        try : 
            coordinate = input("Enter X and Y separated by a space, or enter a non-number to stop: ")
            x,y = coordinate.split()
            x = int(x)
            y = int(y)
            locationlist.append(coordinate)
        except ValueError :
            break
    print("Points: ",locationlist)
    location.where_is_xy(coordinate,locationlist)
    
if(len(locationlist)>=2):
    print("Distances:")
    for i in range(0,len(locationlist)-1):
        a=list(locationlist[i])
        b=list(locationlist[i+1])
        distance=math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)
        print(str(a)+" "+str(b)+" = "+str("%.2f" % round(distance, 2)))

^ This is my main

def where_is_xy(coordinate,locationlist) :
    for coordinate in locationlist :
        templist = coordinate
        x,y = coordinate.split()
        x = int(x)
        y = int(y)
        if x != 0 :
            if y == 0 :
                Point = 'X-Axis.'
            elif x > 0 :
                if y > 0 :
                    Point = 'Quadrant 1.'
                elif y < 0 :
                    Point = 'Quadrant 4.'
            elif x < 0 :
                if y > 0 :
                    Point = 'Quadrant 2.'
                elif y < 0 :
                    Point = 'Quadrant 3.'
        elif x == 0 :
            if y != 0 :
                Point = 'Y-Axis.'
            elif y == 0 :
                Point = 'Origin.'
        print("(",x,",",y,") is ",Point)
        templist(zip(1, 1[1:]))
        print(templist)

^ this is my location.py The output for this function reads:

runfile('C:/Users/aidan/Documents/CS410P/Labs/9L/main.py', wdir='C:/Users/aidan/Documents/CS410P/Labs/9L')
Reloaded modules: location

Enter X and Y separated by a space, or enter a non-number to stop: 1 1

Enter X and Y separated by a space, or enter a non-number to stop: -1 -1

Enter X and Y separated by a space, or enter a non-number to stop: -1 1

Enter X and Y separated by a space, or enter a non-number to stop: 1 -1

Enter X and Y separated by a space, or enter a non-number to stop: 
Points:  ['1 1', '-1 -1', '-1 1', '1 -1']
( 1 , 1 ) is  Quadrant 1.
Traceback (most recent call last):

  File "C:\Users\aidan\Documents\CS410P\Labs\9L\main.py", line 22, in <module>
    location.where_is_xy(coordinate,locationlist)

  File "C:\Users\aidan\Documents\CS410P\Labs\9L\location.py", line 35, in where_is_xy
    templist(zip(1, 1[1:]))

TypeError: 'int' object is not subscriptable

I do not know what causes this error, any help is appreciated. I thought my code was working, but instead I got this error. I am extra confused because there are not even 35 lines of code, only 34 *my code starts at 8.

4
  • 3
    What are you trying to do at templist(zip(1, 1[1:]))? 1[1:] don't make sense. Also you're ignoring argument coordinate, templist isn't a class or function, etc. Commented Jun 17, 2021 at 5:08
  • Um... What do you mean by this: templist(zip(1, 1[1:]))? You cannot make an int subscriptable. Commented Jun 17, 2021 at 5:14
  • @smallvt What are you trying to do with templist(zip(1, 1[1:]))? Commented Jun 17, 2021 at 5:22
  • @MarkSouls, Sujay, nobleknight: oh wow, yeah that is just not meant to be there. I saw it and kept thinking it was part of something else. Thanks. Commented Jun 17, 2021 at 5:27

1 Answer 1

1
templist(zip(1, 1[1:]))

As commenters have noted, this is useless. I removed this and the problem was fixed.

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

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.