-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
38 lines (33 loc) · 1.28 KB
/
main.py
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
32
33
34
35
36
37
38
# importing modules
from turtle import Turtle, Screen
import pandas
# creating screen
screen = Screen()
screen.title("States of India Quiz")
screen.setup(width=630, height=737)
screen.bgpic("India-Map.gif")
# extracting data from "Indian-States.csv" file
data = pandas.read_csv("Indian-States.csv")
states_dict = {row.state:(row.x, row.y) for (index, row) in data.iterrows()}
# some variables to store values
add_guess = 0
answered_states = []
# keep running in the while loop until we input "EXIT" to exit
while True:
# plotting the states by taking the input
guessed_state = screen.textinput(f"{add_guess}/{len(states_dict)} states correct", "Enter a state name 👇").upper()
if guessed_state in states_dict:
answered_states.append(guessed_state)
add_guess += 1
tr = Turtle()
tr.penup()
tr.hideturtle()
tr.goto(states_dict[guessed_state])
tr.write(guessed_state, align="center", font=('Arial', 8, 'bold'))
tr.dot(5)
# creating a csv file of states that we need to learn while exiting
if guessed_state == "EXIT":
missing_states = [state for state in states_dict if state not in answered_states]
new_data = pandas.DataFrame(missing_states)
new_data.to_csv("states-to-learn.csv")
break