I'm fairly new to python and programming in general, and am trying to create some simple programs. I have decided to build a small flashcard program to aid in my study of русский, and have used a dictionary with english definitions as the key, and the русский equivalent as the value. The program runs but I am struggling to figure how I can randomise the word that gets called. I have tried random.choice(vocabulary) but with little success. I have also tried to turn the dictionary key/value pairs into lists but then struggle to call them using the format I have so far used.
Is there a way to randomise the key that gets called using a variation on this script? Further, would a different object type be more useful for such a program? Thanks
import random
vocabulary = {
"to study (imperfective)": "изучать",
"to begin (imperfective)": "начинать",
"to begin (perfective)": "начать"
}
n = 0
while n < 1:
for english, russian in vocabulary.items():
print("Translate:\n" + english + "\n")
answer = input("Answer:\n" )
if answer == russian:
print("Correct!\n")
else:
print("Incorrect! Correct answer: \n" + russian + "\n")
Aucun commentaire:
Enregistrer un commentaire