day 25 - US states game
This commit is contained in:
51
025/50_states.csv
Normal file
51
025/50_states.csv
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
state,x,y
|
||||||
|
Alabama,139,-77
|
||||||
|
Alaska,-204,-170
|
||||||
|
Arizona,-203,-40
|
||||||
|
Arkansas,57,-53
|
||||||
|
California,-297,13
|
||||||
|
Colorado,-112,20
|
||||||
|
Connecticut,297,96
|
||||||
|
Delaware,275,42
|
||||||
|
Florida,220,-145
|
||||||
|
Georgia,182,-75
|
||||||
|
Hawaii,-317,-143
|
||||||
|
Idaho,-216,122
|
||||||
|
Illinois,95,37
|
||||||
|
Indiana,133,39
|
||||||
|
Iowa,38,65
|
||||||
|
Kansas,-17,5
|
||||||
|
Kentucky,149,1
|
||||||
|
Louisiana,59,-114
|
||||||
|
Maine,319,164
|
||||||
|
Maryland,288,27
|
||||||
|
Massachusetts,312,112
|
||||||
|
Michigan,148,101
|
||||||
|
Minnesota,23,135
|
||||||
|
Mississippi,94,-78
|
||||||
|
Missouri,49,6
|
||||||
|
Montana,-141,150
|
||||||
|
Nebraska,-61,66
|
||||||
|
Nevada,-257,56
|
||||||
|
New Hampshire,302,127
|
||||||
|
New Jersey,282,65
|
||||||
|
New Mexico,-128,-43
|
||||||
|
New York,236,104
|
||||||
|
North Carolina,239,-22
|
||||||
|
North Dakota,-44,158
|
||||||
|
Ohio,176,52
|
||||||
|
Oklahoma,-8,-41
|
||||||
|
Oregon,-278,138
|
||||||
|
Pennsylvania,238,72
|
||||||
|
Rhode Island,318,94
|
||||||
|
South Carolina,218,-51
|
||||||
|
South Dakota,-44,109
|
||||||
|
Tennessee,131,-34
|
||||||
|
Texas,-38,-106
|
||||||
|
Utah,-189,34
|
||||||
|
Vermont,282,154
|
||||||
|
Virginia,234,12
|
||||||
|
Washington,-257,193
|
||||||
|
West Virginia,200,20
|
||||||
|
Wisconsin,83,113
|
||||||
|
Wyoming,-134,90
|
||||||
|
BIN
025/blank_states_img.gif
Normal file
BIN
025/blank_states_img.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
53
025/main.py
Normal file
53
025/main.py
Normal 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()
|
||||||
48
025/missing_states.csv
Normal file
48
025/missing_states.csv
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
Alabama
|
||||||
|
Alaska
|
||||||
|
Arkansas
|
||||||
|
California
|
||||||
|
Colorado
|
||||||
|
Connecticut
|
||||||
|
Delaware
|
||||||
|
Florida
|
||||||
|
Georgia
|
||||||
|
Hawaii
|
||||||
|
Idaho
|
||||||
|
Illinois
|
||||||
|
Indiana
|
||||||
|
Iowa
|
||||||
|
Kansas
|
||||||
|
Kentucky
|
||||||
|
Louisiana
|
||||||
|
Maine
|
||||||
|
Maryland
|
||||||
|
Massachusetts
|
||||||
|
Michigan
|
||||||
|
Minnesota
|
||||||
|
Mississippi
|
||||||
|
Missouri
|
||||||
|
Montana
|
||||||
|
Nebraska
|
||||||
|
Nevada
|
||||||
|
New Hampshire
|
||||||
|
New Jersey
|
||||||
|
New Mexico
|
||||||
|
New York
|
||||||
|
North Carolina
|
||||||
|
North Dakota
|
||||||
|
Oklahoma
|
||||||
|
Oregon
|
||||||
|
Pennsylvania
|
||||||
|
Rhode Island
|
||||||
|
South Carolina
|
||||||
|
South Dakota
|
||||||
|
Tennessee
|
||||||
|
Texas
|
||||||
|
Utah
|
||||||
|
Vermont
|
||||||
|
Virginia
|
||||||
|
Washington
|
||||||
|
West Virginia
|
||||||
|
Wisconsin
|
||||||
|
Wyoming
|
||||||
|
3024
025/squirrels.csv
Normal file
3024
025/squirrels.csv
Normal file
File diff suppressed because it is too large
Load Diff
54
025/task.py
Normal file
54
025/task.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# data = []
|
||||||
|
# with open("weather_data.csv") as f:
|
||||||
|
# for line in f.readlines():
|
||||||
|
# data.append(line.strip().split(','))
|
||||||
|
|
||||||
|
# print(data)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
# import csv
|
||||||
|
|
||||||
|
# temperatures = []
|
||||||
|
# with open("weather_data.csv") as f:
|
||||||
|
# reader = csv.reader(f)
|
||||||
|
# next(reader)
|
||||||
|
|
||||||
|
# for row in reader:
|
||||||
|
# temperatures.append(int(row[1]))
|
||||||
|
|
||||||
|
# print(temperatures)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# import pandas as pd
|
||||||
|
|
||||||
|
# data = pd.read_csv("weather_data.csv", delimiter=",")
|
||||||
|
# print(data["temp"].mean())
|
||||||
|
# print(data["temp"].max())
|
||||||
|
|
||||||
|
# output = data[data.temp == data.temp.max()]
|
||||||
|
# print(output)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
data = pd.read_csv("squirrels.csv")
|
||||||
|
|
||||||
|
colors = data["Primary Fur Color"].unique()
|
||||||
|
|
||||||
|
output_colors = []
|
||||||
|
output_count = []
|
||||||
|
for color in colors:
|
||||||
|
if type(color) != str:
|
||||||
|
continue
|
||||||
|
count = len(data[data["Primary Fur Color"] == color])
|
||||||
|
|
||||||
|
output_colors.append(color)
|
||||||
|
output_count.append(count)
|
||||||
|
|
||||||
|
output = {"color": output_colors, "count": output_count}
|
||||||
|
|
||||||
|
df = pd.DataFrame(output)
|
||||||
|
|
||||||
|
print(df.to_csv(index=False))
|
||||||
8
025/weather_data.csv
Normal file
8
025/weather_data.csv
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
day,temp,condition
|
||||||
|
Monday,12,Sunny
|
||||||
|
Tuesday,14,Rain
|
||||||
|
Wednesday,15,Rain
|
||||||
|
Thursday,14,Cloudy
|
||||||
|
Friday,21,Sunny
|
||||||
|
Saturday,22,Sunny
|
||||||
|
Sunday,24,Sunny
|
||||||
|
Reference in New Issue
Block a user