-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path020usStatesGame.py
More file actions
31 lines (28 loc) · 941 Bytes
/
020usStatesGame.py
File metadata and controls
31 lines (28 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import turtle
import pandas
data = pandas.read_csv('50_states.csv',encoding='utf8')
all_states = data.state.to_list()
screen = turtle.Screen()
screen.title('U.S. States')
image = 'blank_states_img.gif'
screen.addshape(image)
turtle.shape(image)
guessed_states = []
while len(guessed_states)<50:
answer_state = screen.textinput(title=f'{len(guessed_states)}/50 States', prompt='Whats another states name?')
if answer_state == '':
missing_states = []
for state in all_states:
if state not in guessed_states:
missing_states.append(state)
new_data = pandas.DataFrame(missing_states)
new_data.to_csv('states_to_learn.csv')
break
if answer_state in all_states:
t = turtle.Turtle()
t.hideturtle()
t.penup()
state_data = data[data.state == answer_state]
t.goto(int(state_data.x),int(state_data.y))
t.write(state_data.state.item())
guessed_states.append(state_data.state.item())