File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
GAMES/Guess the US States Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ import turtle
2
+ import pandas
3
+
4
+
5
+ df = pandas .read_csv ("50_states.csv" )
6
+ screen = turtle .Screen ()
7
+ screen .title ("U.S. States Game" )
8
+ img_gif = "blank_states_img.gif"
9
+ screen .addshape (img_gif )
10
+ # register the shape
11
+ turtle .shape (img_gif )
12
+ state_list = df .state .to_list ()
13
+ guessed_states = []
14
+
15
+
16
+ def reveal_state (x , y ):
17
+ name = turtle .Turtle ()
18
+ name .hideturtle ()
19
+ name .penup ()
20
+ name .goto (x , y )
21
+ name .write (f"{ ans } " )
22
+
23
+
24
+ while len (guessed_states ) < 50 :
25
+ ans = screen .textinput (title = f" Score: { len (guessed_states )} /50" , prompt = "Name a State: " ).title ()
26
+
27
+ if ans == "exit" .title ():
28
+ correction = [state for state in state_list if state not in guessed_states ]
29
+
30
+ ans_file = pandas .DataFrame (correction )
31
+ ans_file .to_csv ("correct_ans." )
32
+ break
33
+
34
+ # ALl the states you have missed will be written in the correct_ans.csv file
35
+
36
+ if ans in state_list :
37
+ guessed_states .append (ans )
38
+ state_data = df [df .state == ans ]
39
+ x_cor = state_data .x
40
+ y_cor = state_data .y
41
+ reveal_state (int (x_cor ), int (y_cor ))
42
+
43
+
44
+ # def get_mouse_click_coordinate(x, y):
45
+ # print(x, y)
46
+
47
+ # turtle.onscreenclick(get_mouse_click_coordinate)
48
+ # Get turtle coordinates on image
49
+ # These co ordinates were inserted in 50_states.csv
50
+
51
+ screen .exitonclick ()
You can’t perform that action at this time.
0 commit comments