Memory game with Python in no time

13/07/2019

Do you want to learn long list of names having fun? I got the program for you. You can build your own when you want changing the list of names you want to learn. In the following example, explained in the video, I will show you how to create the program to help people to memorize list of names having fun. The example, in particular, will test your memory about the countries that uses the euro as their country money. As you know there are several countries that uses euro, but not all the european countries uses them. So, which is the best way than a test to ensure that you remember them all? But you can substitute the list whith anything else you want and also compare it with your friends result as a game.

How to memorize lists of names in the most effective and fun way with a couple of lines of code in Python. In 3 minutes (even less) you will be able to create this program, understanding lists, list comprehension, for loops, the use of print and input. With a very basic knowledge of Python you can get a lot of fun (and learning). You will be able to create a lot of memory games to test yourself and your friends ability in memorizing stuffs.

The code of the memory game

Here is the code that you have seen in the video about making a game to test your memory about list of names. In this example you have to mermorize the countries that uses the euro currency.

The program uses the SAPI.SpVoice of Windows 10 to make the computer speak during the game.

import sys
from win32com.client import Dispatch
speak = Dispatch("SAPI.SpVoice")
ls = sorted("""
Austria
Italia
Germania
Francia
Lussemburgo
Grecia
Spagna
Portogallo
Malta
Cipro
Lettonia
Lituania
Estonia
Finlandia
Slovacchia
Slovenia
Irlanda
Paesi Bassi""".split("\n")[1:])

def start():
	print("I paesi dell'Euro sono:\n")

	for paese in ls:
		print(paese[0] + "."*(len(paese)-2) + paese[-1])
		x = input(paese[0])
		if paese[0] + x == paese:
			#print(ls.index(paese) + 1)
			speak.Speak(paese)
			continue
		else:
			print("Mi spiace, hai sbagliato")
			print("Dovevi scrivere:" + paese)
			print("Punti: " + str(paese.index(paese)))
			y = input("Vuoi riprovare?")
			if y in "Si SI si sì Sì".split():
				start()
			else:
				print("Riprova... il tuo punteggio è " + str(ls.index(paese)))
				break
	print("Bravo... il tuo punteggio è " + str(ls.index(paese)))


start()

 

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.