Python实现美国国家游戏US States Game

37次阅读
没有评论

共计 904 个字符,预计需要花费 3 分钟才能阅读完成。

美国国家游戏

针对美国各州名称测试您的知识。

import turtle
import pandas

screen = turtle.Screen()
screen.title("U.S. States Game")
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)}/50 States Correct",
                                    prompt="What's another state's name?").title()
    if answer_state.lower() == "exit":
        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:
        guessed_states.append(answer_state)
        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)

关联资源下载

包含 2 个文件:50_states.csv 和 blank_states_img.gif。

下载地址:https://gaga.lanzoum.com/i1K1R0s824oh

正文完
post-qrcode
 0
三毛
版权声明:本站原创文章,由 三毛 于2023-08-01发表,共计904字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)