U.S State guessing game using Python
Introduction:
This game is very simple and easy to make. Using python and turtle library, this game is made in a simple way. User guesses the name of the U.S states and if the guess is right, the name will be printed in respective coordinate. And if the user guesses all the state right game will end, or if the user type secret code: "exit" the game will again exit.
How to exit the game:
1. Complete all the answers
2. or Type "exit" as a secret code
Code:
main.py
import turtle
import pandas
data = pandas.read_csv("50_states.csv")
all_state = data["state"].to_list()
title_score = 0
screen = turtle.Screen()
image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)
correct_answer = []
while len(correct_answer) < 50:
answer = screen.textinput(title=f"{len(correct_answer)}/50 States correct", prompt="Enter the name of states:").title()
if answer == "Exit":
missing_answer = [s for s in data['state'] if s not in correct_answer]
df = pandas.DataFrame(missing_answer)
df.to_csv("answer.csv")
break
for state in data['state']:
state_data = data[data["state"] == answer]
if state == answer and answer not in correct_answer:
t = turtle.Turtle()
correct_answer.append(answer)
t.hideturtle()
t.penup()
t.goto(int(state_data.x), int(state_data.y))
t.write(f"{answer}", move=False, align="center", font=("Arial", 8, "normal"))create "50_states.csv" file and paste following code
state,x,y
Alabama,139,-77
Alaska,-204,-170
Arizona,-203,-40
Arkansas,57,-53
California,-297,13
Colorado,-112,20
Connecticut,297,96
Delaware,275,42
Florida,220,-145
Georgia,182,-75
Hawaii,-317,-143
Idaho,-216,122
Illinois,95,37
Indiana,133,39
Iowa,38,65
Kansas,-17,5
Kentucky,149,1
Louisiana,59,-114
Maine,319,164
Maryland,288,27
Massachusetts,312,112
Michigan,148,101
Minnesota,23,135
Mississippi,94,-78
Missouri,49,6
Montana,-141,150
Nebraska,-61,66
Nevada,-257,56
New Hampshire,302,127
New Jersey,282,65
New Mexico,-128,-43
New York,236,104
North Carolina,239,-22
North Dakota,-44,158
Ohio,176,52
Oklahoma,-8,-41
Oregon,-278,138
Pennsylvania,238,72
Rhode Island,318,94
South Carolina,218,-51
South Dakota,-44,109
Tennessee,131,-34
Texas,-38,-106
Utah,-189,34
Vermont,282,154
Virginia,234,12
Washington,-257,193
West Virginia,200,20
Wisconsin,83,113
Wyoming,-134,90
Download the following image file and paste it to your project directory
Comments
Post a Comment