Files
python_bootcamp/025/main.py
Tanguy Deleplanque ce3befd167 day 26 - comprehensions
2025-07-17 09:37:07 +02:00

52 lines
1.3 KiB
Python

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":
missing_states = [ s for s in data.states if s not in found_states ]
output = pd.DataFrame(missing_states)
output.to_csv("missing_states.csv")
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()