from turtle import Turtle, Screen import pandas as pd FONT = ("Courier", 14, "normal") screen = Screen() screen.setup(725,491) screen.bgpic('blank_states_img.gif') screen.tracer(0) data = pd.read_csv("50_states.csv") # state, x, y game_on = True states_remaining = len(data) found_states = [] while len(found_states) < 50: guess = str(screen.textinput(f"{states_remaining} states to find", "Find a state:")) if guess == "None": with open("missing_states.csv", "w") as f: for a_state in data.state: if a_state not in found_states: f.write(f"{a_state}\n") exit() state = data[data.state == guess.title()] # if the subset is not empty, it means the state is in the list if len(state) > 0: x_pos = state.x.item() #state.iloc[0]["x"] y_pos = state.y.item() #state.iloc[0]["y"] state_name = state.iloc[0]["state"] if state_name in found_states: continue states_remaining -= 1 found_states.append(state_name) text = Turtle() text.pu() text.color("black") text.hideturtle() text.goto(x_pos, y_pos) text.write(state_name, align="center", font=FONT) screen.update() screen.mainloop()