This shows you how to create a flashcard like quiz game using a Python dictionary. It's up to you to explore the approach and make this a more meaningful game.
Creating a flashcard-like quiz game (Python)
''' quiz_dictionary_style101.py
using a keyword:definitions_list dictionary for a flashcard-like quiz
tested with Python27 and Python33 by vegaseat 08nov2013
'''
import random
# make string input work with Python2 or Python3
try: input = raw_input
except: pass
# a simple sample dictionary 'pick the right color'
# keyword:[def1, def2, def3, correct_def_ix]
# could use module pickle to dump/load this dictionary
mydict = {
'sun' : ['black', 'yellow', 'blue', 1],
'water' : ['red', 'white', 'blue', 2],
'grass' : ['white', 'green', 'orange', 1],
'coal' : ['black', 'purple', 'red', 0]
}
keyword_list = list(mydict.keys())
# shuffle the keywords in place
random.shuffle(keyword_list)
print('Pick the right color:')
correct = 0
wrong = 0
for keyword in keyword_list:
sf = '''\
{}
A) {}
B) {}
C) {}
'''
print(sf.format(keyword, mydict[keyword][0],
mydict[keyword][1],mydict[keyword][2]))
letter = input("Enter letter of your choice (A B C): ").upper()
if letter == 'ABC'[mydict[keyword][3]]:
print('correct')
correct += 1
else:
print('wrong')
wrong += 1
print('-'*30)
# final
sf = "Answers given --> {} correct and {} wrong"
print(sf.format(correct, wrong))
EarthHorse 0 Newbie Poster
EarthHorse 0 Newbie Poster
EarthHorse 0 Newbie Poster
EarthHorse 0 Newbie Poster
EarthHorse 0 Newbie Poster
EarthHorse 0 Newbie Poster
EarthHorse 0 Newbie Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
EarthHorse 0 Newbie Poster
Doug_2 0 Newbie Poster
Chance_1 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.