Today, we will take a look at some very simple code to make a quiz in python. Yes, it's really easy. Just one file, some data and a couple of lines of code. You can paste this code in Jupyter notebook, click ctrl + enter and you're done. Next time we will tell how to use py2exe to make a program from this that doesn't need python to run on windows. See ya.
fruit = """frutta
le fruit
verdura
le légume
anguria
la pastèque
banana
la banane
mela
la pomme
noce di cocco
la noix de coco
arancia
une orange
prugna secca
le pruneau
noce
la noix
limone
le citron
uva sultanina
le raisin sec
acino d'uva
le raisin
melone
le melon
pesca
la pêche
prugna
la prune
broccoli
le brocoli
pomodoro
la tomate
lattuga
la laitue
cipolla
un oignon
cavolo
le chou
zucca
la citrouille
carota
la carotte
pisello
le petit pois
fagiolo
le haricot
patata
la pomme de terre
cavolfiore
le chou-fleur
cetriolo
le concombre
peperone
le poivron
melanzana
une aubergine
pera
la poire
spinaci
les épinards
ciliegia
la cerise"""
def createdic(vocabulary):
'insert a list in which a line is in italian, the other in french'
voc = {}
arr = vocabulary.split("\n")
ita = [i for i in arr if arr.index(i)%2==0]
fra = [i for i in arr if arr.index(i)%2!=0]
voc = {k:v for k,v in zip(ita,fra)}
return voc
voc = createdic(fruit)
for k in voc:
print(k)
ans = input("? ")
if ans == voc[k]:
print('giusto\n')
else:
print("sbagliato, era ", voc[k],"\n")
Comments
Post a Comment