top of page

State guessing game

  • Writer: 라임 샹큼
    라임 샹큼
  • Mar 26
  • 1 min read

Updated: Mar 27

Game where there is a picture and the correct text you input flies to the place where the state is.


import turtle

import pandas

import time


n = 0

FONT = ('Arial',7,'normal')


#state turtle - move to states

state = turtle.Turtle()

state.hideturtle()

state.penup()

state.speed('fastest')


#solely for text that is displayed

text = turtle.Turtle()

text.hideturtle()

text.penup()

text.speed('fastest')


#screen management

screen = turtle.Screen()

screen.title('US states guess game')

image = 'blank_states_img.gif'

screen.addshape(image)

turtle.shape(image)





data = pandas.read_csv('50_states.csv')

states = data['state'].to_list()


game_is_on =True

while game_is_on:

    title = f'US states game: {n}/50' #this has to be refreshed too

    state_answer = (screen.textinput(title=title, prompt='What\'s a state name')).title()


    if state_answer in states:

        n += 1

        x_cor = int(data[data['state'] == state_answer].x)

        y_cor = int(data[data['state']==state_answer].y)

        state.goto(x = x_cor, y = y_cor)

        state.write(arg = state_answer,font = FONT)


    else:

        text.goto(-300,0)

        text.write(arg='Wrong input, guess again', font= ('Arial', 50, 'normal'))

        time.sleep(1.3)

        text.clear()

    if n == 50:

        game_is_on = False




screen.exitonclick()

##make sure to put refresh needing things inside loop

 
 
 

Recent Posts

See All
Stock market price alerter

Lately I’ve been getting API data from existing data and using it to get actual live data. This is done by importing requests.  This was...

 
 
 
Making a better quiz ui

I reencountered classes again. I remember I had a a hard time learning how classes were different from simply defining functions. It was...

 
 
 
Getting quotes and displaying them

from tkinter import * import requests def get_quote():     quote_url = requests.get(url=' https://api.kanye.rest ')     quote_json =...

 
 
 

Comments


© 2024 by GifTED. Powered and secured by Wix

bottom of page