What is the capital of New York? A game on the command line in Python

As we did recently with another post, we want to make a very simple game to learn something, to help memorize stuff in a fun way. This time we will make you test your knowledge about the capitals of the US. The code is this and you can watch the video with the live scripting for the game.

from random import shuffle
from win32com.client import Dispatch
speak = Dispatch("SAPI.SpVoice")

capitals = [("Montgomery"," Alabama"),
("Juneau"," Alaska"),
("Phoenix"," Arizona"),
("Little Rock"," Arkansas"),
("Sacramento"," California"),
("Denver"," Colorado"),
("Hartford"," Connecticut"),
("Dover"," Delaware"),
("Tallahassee"," Florida"),
("Atlanta"," Georgia"),
("Honolulu"," Hawaii"),
("Boise"," Idaho"),
("Springfield"," Illinois"),
("Indianapolis"," Indiana"),
("Des Moines"," Iowa"),
("Topeka"," Kansas"),
("Frankfort"," Kentucky"),
("Baton Rouge"," Louisiana"),
("Augusta"," Maine"),
("Annapolis"," Maryland"),
("Boston"," Massachusetts"),
("Lansing"," Michigan"),
("Saint Paul"," Minnesota"),
("Jackson"," Mississippi"),
("Jefferson City"," Missouri"),
("Helena"," Montana"),
("Lincoln"," Nebraska"),
("Carson City"," Nevada"),
("Concord"," New Hampshire"),
("Trenton"," New Jersey"),
("Santa Fe"," New Mexico"),
("Albany"," New York"),
("Raleigh"," North Carolina"),
("Bismarck"," North Dakota"),
("Columbus"," Ohio"),
("Oklahoma City"," Oklahoma"),
("Salem"," Oregon"),
("Harrisburg"," Pennsylvania"),
("Providence"," Rhode Island"),
("Columbia"," South Carolina"),
("Pierre"," South Dakota"),
("Nashville"," Tennessee"),
("Austin"," Texas"),
("Salt Lake City"," Utah"),
("Montpelier"," Vermont"),
("Richmond"," Virginia"),
("Olympia"," Washington"),
("Charleston"," West Virginia"),
("Madison"," Wisconsin"),
("Cheyenne"," Wyoming")]

shuffle(capitals)

for cap in capitals:
	capital, state = cap
	print(f"Which is the capital of {state}")
	answer = input(">")
	ug = 0
	for l in answer:
		if l in capital:
			ug += 1
	typo = (len(capital) - ug) < 2
	if answer.lower() == capital.lower() or typo:
		speak.Speak("Bravo")
	else:
		print(f"Wrong! The answer was {capital}.\nYour score is {capitals.index(cap)}")
		break


Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.