day 25 - US states game

This commit is contained in:
Tanguy Deleplanque
2025-07-16 18:41:16 +02:00
parent c34b9d4c52
commit 612ad7c549
7 changed files with 3238 additions and 0 deletions

53
025/main.py Normal file
View File

@ -0,0 +1,53 @@
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()