25일차에서 살펴본 pandas로 csv 파일을 읽고 데이터를 활용하는 게임이다.
import turtle
import pandas
screen = turtle.Screen()
screen.title("U.S States Game")
screen.setup(725,491)
image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)
data = pandas.read_csv("50_states.csv")
all_states = data.state.to_list()
guessed_states = []
while len(guessed_states) < 50 :
answer_state = screen.textinput(title=f"{len(guessed_states)}/{len(all_states)} 주를 맞췄습니다.",prompt="주의 이름은 무엇인가요>").title()
if answer_state == "Exit" :
missing_state = []
for state in all_states :
if state not in guessed_states :
missing_state.append(state)
new_data = pandas.DataFrame(missing_state)
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(answer_state)
guessed_states.append(answer_state)
screen.exitonclick()
import turtle
import pandas
screen = turtle.Screen()
screen.title("U.S States Game")
screen.setup(725,491)
image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)
data = pandas.read_csv("50_states.csv")
all_states = data.state.to_list()
guessed_states = []
while len(guessed_states) < 50 :
answer_state = screen.textinput(title=f"{len(guessed_states)}/{len(all_states)} 주를 맞췄습니다.",prompt="주의 이름은 무엇인가요>").title()
if answer_state == "Exit" :
missing_state = []
for state in all_states :
if state not in guessed_states :
missing_state.append(state)
new_data = pandas.DataFrame(missing_state)
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(answer_state)
guessed_states.append(answer_state)
screen.exitonclick()