#πŸ”’ How can I fix this error?

32 messages Β· Page 1 of 1 (latest)

silver hedge
#

i'm trying to get it to print a grid and display a point on it but im getting this error:
if currentPoint in points:
^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'in <string>' requires string as left operand, not tuple

hallow onyxBOT
#

@silver hedge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

silver hedge
#
import string


cols = 15
rows = 15

print("Please input your point in a [()] bracket.")

points: str = input("Please input your point.")
for y in range(rows//2, -(rows//2) - 1, -1):
    for x in range(-(cols//2), cols//2 + 1, 1):
        currentPoint = (x,y)
        if currentPoint in points:
            print("X", end = "")
    
        if currentPoint == (0, 0):
            print("+", end = "")
        if x == 0:
            print ("|", end = "")
        if y == 0:
            print("-", end = "")
        else:
            print(" ", end= "")
    print()
#

this is my current code

hot anchor
#

what do you tihnk that if statement is doing there?

hot anchor
#

what do you think that line is doing?

#

the if currentPoint in points:

silver hedge
hot anchor
#

if the if statement checks in

#

its supposed to happen IF currentPoint is in points

#

if currentPoint in points:

#

what are you saying currentPoint is in the code?

silver hedge
#

where the point is placed

hot anchor
#

what exactly is that variable?

#

what type of variable

silver hedge
hot anchor
hot anchor
#

you can't check if a tuple is in a string

#

now what you can do

#

is make the currentPoint a string with the format (x,y)

#

and you do that by formatting string

#

like this

currentPoint = f"({x},{y})"```
#

let me know if that works

silver hedge
#

oh thank you

silver hedge
#

i see where i went wrong

hot anchor
#

nice

hallow onyxBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.